c# - Cannot Split Table with EF 5 - Code First - with existing database -


i trying split legacy user table 2 entities using 1 one mapping keep getting migration errors stating database out of sync, though (i think mapped) , trying make one-to-one relationship.

this existing database (although using code first migrations become important down line) have not added changes database (although unsure one-to-one table split expects), keep getting this:

the model backing 'context' context has changed since database created.     consider using code first migrations update database 

i can update database (either manually or via migrations) have no idea out of sync no new fields have been added , names match up.

baseentity:

public abstract class baseentity<t> {     [key]     public t id { get; set; }     public datetime createdon { get; set; } } 

membership model:

public class membership : baseentity<guid> {     public string username { get; set; }     public bool approved { get; set; }     public bool locked { get; set; }     public profile profile { get; set; } } 

profile model:

public class profile : baseentity<guid> {     public string firstname { get; set; }     public string lastname { get; set; }     public string email { get; set; }     public string telephone { get; set; }     public string extension { get; set; }     public membership membership { get; set; } } 

membership mapping (this has 1 1 definition):

public class membershipmap : entitytypeconfiguration<membership> {     public membershipmap()     {         //primary key         this.haskey(t => t.id);          //**relationship mappings         this.hasrequired(m => m.profile)             .withrequiredprincipal(p => p.membership);          //properties & column mapping         this.property(m => m.id)             .hascolumnname("pkid")             .hasdatabasegeneratedoption(databasegeneratedoption.none);          this.property(m => m.username)             .hascolumnname("username")             .hasmaxlength(255);          this.property(m => m.approved)             .hascolumnname("isapproved");          this.property(m => m.locked)             .hascolumnname("islocked");          this.property(m => m.createdon)             .hascolumnname("creationdate");          this.totable("appuser");     } } 

profile mapping:

public class profilemap : entitytypeconfiguration<profile> {     public profilemap()     {         //primary key         this.haskey(t => t.id);          //properties & column mapping         this.property(m => m.id)             .hascolumnname("pkid")             .hasdatabasegeneratedoption(databasegeneratedoption.none);          this.property(m => m.firstname)             .hascolumnname("firstname");          this.property(m => m.lastname)             .hascolumnname("lastname");          this.property(m => m.email)             .hascolumnname("email");          this.property(m => m.telephone)             .hascolumnname("telephone");          this.property(m => m.extension)             .hascolumnname("extension");          this.totable("appuser");     } } 

database table know not fields mapped, not need them @ stage, surely wouldn't issue it?

appuser database table

issue not code first mappings caused me switching databases , rouge migrations coming play.

to reset migrations can see answer here follow question:

resetting context entity framework 5 thinks working initialised database - code first

kudos evilbhonda


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -