Invalid object name 'dbo.EdmMetadata' and 'dbo.__MigrationHistory'

entity-framework

Question

I am using Entity Framework 5 and doing a simple query to get a few users from a table.

The SQL database is already created so I use my entities as a way to map what I have.

When I run my query I detect that other queries were executed and 2 of them with errors:

QUERY 1

ERROR: Invalid object name 'dbo.__MigrationHistory'.

SELECT
[GroupBy1].[A1] AS [C1]
FROM ( 
    SELECT
        COUNT(1) AS [A1]
    FROM [dbo].[__MigrationHistory] AS [Extent1]
) AS [GroupBy1]

QUERY 2

ERROR: Invalid object name 'dbo.EdmMetadata'.

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

Why is that?

I do not have dbo.EdmMetadata and dbo.__MigrationHistory tables in my database as the database already existed.

How to solve this?

1
29
10/15/2013 11:24:45 AM

Popular Answer

Since the database is already there you will not have dbo.EdmMetadata and dbo.__MigrationHistory which codefirst is expecting. And to resolve this you can try to set the SetInitializer to null.

 static NameOfYourContext()
 {
   Database.SetInitializer<NameOfYourContext>(null);        
 }      

You can see this in the comments section of the this post by Scott Gu

55
10/15/2013 2:38:40 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow