0
votes

I create a model that hasnt any relation to another tables with EF. when I add it in the context and run app for create database i had an Error in Application-start:

One or more validation errors were detected during model generation: System.Data.Edm.EdmEntityType: : EntityType 'UrlHelper' has no key defined. Define the key for this EntityType. System.Data.Edm.EdmEntityType: : EntityType 'RequestContext' has no key defined. Define the key for this EntityType. System.Data.Edm.EdmEntityType: : EntityType 'HttpContextBase' has no key defined. Define the key for this EntityType. System.Data.Edm.EdmEntityType: : EntityType 'Exception' has no key defined. Define the key for this EntityType. System.Data.Edm.EdmEntityType: : EntityType 'Type' has no key defined. Define the key for this EntityType.

Code in my global.asax is like below:

    public class MyInitializer
: DropCreateDatabaseIfModelChanges<DBTa>
    {
    }
    protected void Application_Start()
    {
        //for creating and 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 i removed model from app my problem solved, but i need this Model.

please help thanks a lot

1

1 Answers

0
votes

You should set "key" property in your 'UrlHelper' model. If you use EF code first - in your model you should add attribute [Key] to one of its properties. If you use model first approach - in your model you should mark one of properties as primary key. If you use Database first approach - you should create primary key in table.