Mixins with C# 4.0

You can create mixin-like constructs in C# 4.0 without using dynamic, with extension methods on interfaces and the ConditionalWeakTable class to store state. Take a look here for the idea. Here’s an example: public interface MNamed { // required members go here } public static class MNamedCode { // provided methods go here, as extension … Read more

Can’t get EntityFunctions.TruncateTime() to work

I faced this problem recently when I upgraded my Web Application from Entity Framework 5 to Entity Framework 6. Then, I realized that System.Data.Entity DLL needs to be removed from the application completely in order to work with Entity Framework 6. Entity Framework 6 is not part of .NET Framework anymore and therefore it is … Read more

Best ORM to use with C# 4.0 [closed]

UPDATE 2016 Six years later things are VERY different. NHibernate is all but abandoned, other alternatives were abandoned (eg Subsonic), Entity Framework is perhaps the most common full-featured ORM, and people have been moving to micro ORMs like Dapper for years, to map from queries to objects with a minimum of overhead. The application scenarios … Read more

How to handle hierarchical routes in ASP.NET Web API?

Configure the routes as below. The {param} is optional (use if you need): routes.MapHttpRoute( name: “childapi”, routeTemplate: “api/Parent/{id}/Child/{param}”, defaults: new { controller = “Child”, param = RouteParameter.Optional } ); routes.MapHttpRoute( name: “DefaultApi”, routeTemplate: “api/{controller}/{id}”, defaults: new { id = RouteParameter.Optional } ); Then call the child APi as /api/Parent/1/child The parent can be called simple … Read more

Assigning a GUID in C#

If you already have a string representation of the Guid, you can do this: Guid g = new Guid(“11223344-5566-7788-99AA-BBCCDDEEFF00”); And if you want a brand new Guid then just do Guid g = Guid.NewGuid();

The directory ‘/website/App_Code/’ is not allowed because the application is precompiled

Depending on your case, there are three possible scenarios: see this link http://www.beansoftware.com/ASP.NET-FAQ/Directory-App_Code-Not-Allowed.aspx Basically, If you precompiled your app, there shoudn’t be an App_Code folder. If you added it later, you should delete it. OR May be Somehow a precompiled.config file has made it to production. Deleting that file should resolve the App_Code directory error.