7

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 :)

1
  • I saw this table show up in my Dynamic Data website, the approach suggested below removed it. Commented Jul 2, 2012 at 15:25

1 Answer 1

10

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>();
Sign up to request clarification or add additional context in comments.

4 Comments

"There is no Code-First against an existing database". er .. are you sure?? The EF team says otherwise: "This walkthrough is going to demonstrate Code First generating the database schema but the same principals apply to mapping to an existing database, with the exception of ‘7." blogs.msdn.com/b/adonet/archive/2011/03/15/…
I didn't mean that fluent mapping doesn't work with existing db. It does but it is not code first. Code first means that you create pocos and mapping first and database is generated from these informations.
It's a wash for me...you were being overly semantic in your first statement (-1). But your second statement was spot on (+1)
Hm, this all makes sense and I added that line to my OnModelCreating method, but in LINQPad I'm still seeing the EdmMetadata table being queried...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.