March 2012 Blog Posts

Entity Framework #2–my scattered notes Part 2

This is my second post about my Entity Framework Code First usage experience. You can find my first post here. The Entity Framework Power Tool is a must-have tool for those who use EF in Code First mode, especially with fluent API. With this tool you can reverse-engineering an existing data source and then generate both domain classes (POCO) and the mapping configuration files. The latter are generated by creating a class which inherits from EntityConfiguration<T>, where T is your domain entity type. The tools is able to understand all the existing relations in the database and to transform...

posted @ Thursday, March 29, 2012 12:02 PM | Feedback (0)

Entity Framework #2–my scattered notes Part 1

Here are a few scattered notes on the use of Entity Framework 4.2 Code First: The core EF Api is contained in the System.Data.Entity.dll assembly The DbContext Object is a lightweight version of the ObjectContext object, the former provides more functionality than the first. If you need to get an ObjectContext instance starting from a DbContext instance you can use the IObjectContextAdapter interface for casting, as shown in the following example: 1: (myDbContext as IObjectContextAdapter).ObjectContext; The DbSet...

posted @ Thursday, March 22, 2012 6:05 PM | Feedback (0)

Entity Framework #1 –How to get the original type of an entity when dynamic proxy is enabled

If your Entity Framework context is proxy-enabled, the runtime will create a proxy instance of your entities, i.e. a dynamically generated class which inherits from your entity class and overrides its virtual properties by inserting specific code useful for example for tracking changes and lazy loading. The proxy instance has a dynamically generated name by the runtime that looks like this: {System.Data.Entity.DynamicProxies User_00394CF1F92740F13E3EDBE858B6D599DFAF87AA5A089245977F61A32C75AA22} (User is the original entity class name which the proxy class inherited from). Starting from the proxy type, if you need to know the original type you have to use the static method...

posted @ Tuesday, March 13, 2012 6:09 PM | Feedback (0)