Disable or turn off the auto generation of mappings based on the POCO properties RRS feed

  • Question

  • I am using the Code First constructs to connect to an existing database (which, I know is not code first technically).  I do this so that I can mock out Fake Data Repositories using LINQ to Entities instead of LINQ to SQL.  In the CTP3 last year, this worked great - I could create a new Configuration for my table, and explicitly add the properties of the POCO that were mapped to the database.

    In July 2011, Code First was included in EF4.1 so I thought I would upgrade.  Unfortunately, EF is now too smart for my liking. For example, a) all properties of my POCOs are assumed to be mapped to database fields, so for example, a property Person.TempPassword{get;set;} causes the generated SQL to search for a TempPassword column in my Person table; b) if I inherit a class from my POCO (for example, Employee inherits from Person), EF starts generating Discriminator columns etc.

    I know that I can resolve the former problem using the Ignore() or [NotMapped] attributes, however that is a big hassle and I'd prefer not to do it. The latter problem I cannot resolve.

    All I need is a way to be able to turn off all these smarts, and just let me explicitly set properties as I used to do.  Note that I have tried removing every single one of the constraints as well, for example modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

    I have also overriden the call to OnModelCreating(), and NOT called base.OnModelCreating(), just included my own Configuration code, as below.

    An example of my configuration is:


    public class AddressBookConfiguration : EntityTypeConfiguration<AddressBook>{
        public AddressBookConfiguration()
    	this.HasKey(x => x.AddressBookID);
    	this.Property(x => x.AddressBookID);
    	this.Property(x => x.AddressBookName);
    	this.Property(x => x.WhenCreated);
    	this.Property(x => x.TotalItems);

    Thank you.


    • Edited by Ben Liebert Sunday, September 25, 2011 8:19 PM Forgot update.
    Sunday, September 25, 2011 8:17 PM


All replies