2

I have an existing DB and I have used the EF 4.1 code first to map my POCO objects to the tables. But I get the this error:

EF 4.1 Error Model compatibility cannot be checked because the EdmMetadata type

Eventhough I have added the OnModelCreating method it still gives me the same error:

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
{     
    modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); 
}

My POCO and DB Table are exactly identical.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
Shuaib
  • 1,561
  • 3
  • 19
  • 28

1 Answers1

2

It looks like the issue is that the database exists yet you are trying to create it using EF CodeFirst. If you drop the database, this will most likely run and it will create the database and the table. Here is a link to a person that had this issue and that is how they resolved it:

http://forums.asp.net/t/1673379.aspx/1?Unable+to+generate+Edm+Metadata+table+at+runtime+from+EF+code+first+model

If you wanted to use your existing database (in case you had other data in it), I think you need to modify what Code First expects. Here is a SO article on how to do this:

Entity Framework CTP 4 - Code First Custom Database Initializer

Make sure you read all the posts because even the ones not accepted as the answer have some great information on things you can do.

Community
  • 1
  • 1
IAmTimCorey
  • 16,412
  • 5
  • 39
  • 75
  • Thanks BiggsTRC, deleting the database seemed to worked. I created the DB using EF and then moved the data from the existing database tables. – Shuaib May 09 '11 at 19:26
  • 2
    I found this blog post that actually fixed my issue. The key was to Initialize the Contex: Database.SetInitializer(null); http://agilenet.wordpress.com/2011/04/11/entity-framework-4-1-rc-with-an-existing-database/ – Shuaib May 10 '11 at 00:58
  • @Shuaib - Great! Glad you got a solution. Thanks for providing the solution. – IAmTimCorey May 10 '11 at 01:03