asp.net mvc 3 - MVc error with EF -
i create model hasnt relation tables ef. when add in context , run app create database had error in application-start:
one or more validation errors detected during model generation: system.data.edm.edmentitytype: : entitytype 'urlhelper' has no key defined. define key entitytype. system.data.edm.edmentitytype: : entitytype 'requestcontext' has no key defined. define key entitytype. system.data.edm.edmentitytype: : entitytype 'httpcontextbase' has no key defined. define key entitytype. system.data.edm.edmentitytype: : entitytype 'exception' has no key defined. define key entitytype. system.data.edm.edmentitytype: : entitytype 'type' has no key defined. define key entitytype.
code in global.asax below:
public class myinitializer : dropcreatedatabaseifmodelchanges<dbta> { } protected void application_start() { //for creating , initializing database system.data.entity.database.setinitializer(new myinitializer()); **dbta db = new dbta();**//error shows here db.database.initialize(true); // arearegistration.registerallareas(); registerglobalfilters(globalfilters.filters); registerroutes(routetable.routes); }
but when removed model app problem solved, need model.
please lot
you should set "key" property in 'urlhelper'
model. if use ef code first - in model should add attribute [key]
1 of properties. if use model first approach - in model should mark 1 of properties primary key. if use database first approach - should create primary key in table.
Comments
Post a Comment