Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Entity Framework Code-First (with an existing DB) keep trying get data from an EdmMetadata table?

i'm trying do some Entity Framework Code First programming to an existing database .. but I keep seeing this code in my Sql Profiler :-

SELECT   TOP ( 1 ) [Extent1].[Id]        AS [Id],
                   [Extent1].[ModelHash] AS [ModelHash]
FROM     [dbo].[EdmMetadata] AS [Extent1]
ORDER BY [Extent1].[Id] DESC

What the hell is this EdmMetadata table and why do is my EF code trying to grab the Id and ModelHash from there?

Remember, I'm trying to work against an existing DB.

Cheers :)

like image 551
Pure.Krome Avatar asked Mar 21 '11 04:03

Pure.Krome


People also ask

Which is better code first or database first in Entity Framework?

3)Database Version Control Versioning databases is hard, but with code first and code first migrations, it's much more effective. Because your database schema is fully based on your code models, by version controlling your source code you're helping to version your database.

What is EdmMetadata?

EdmMetadata table keeps hash of current code-first model and it allows DbContext detecting changes of model so that database can be recreated. This feature is turned on by default.

What is the difference between code first and database first?

In the code first approach, the programmer has to write the classes with the required properties first, while in the database first approach, the programmer has to create first the database using GUI.


1 Answers

There is no Code-First against existing database. If you have database you are doing Database-first. In such case your mapping is driven by database.

EdmMetadata table keeps hash of current code-first model and it allows DbContext detecting changes of model so that database can be recreated. This feature is turned on by default. You can turn it off by removing convention in OnModelCreating:

modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
like image 144
Ladislav Mrnka Avatar answered Sep 21 '22 09:09

Ladislav Mrnka