无效的对象名称“dbo.EdmMetadata”和“dbo .__ MigrationHistory” [英] Invalid object name 'dbo.EdmMetadata' and 'dbo.__MigrationHistory'
问题描述
我已经创建了SQL数据库,因此我使用我的实体作为一个方法来映射我有什么。
当我运行我的查询时,我发现其他查询已被执行,其中2个错误:
QUERY 1
错误:无效的对象名称dbo .__ MigrationHistory / p>
SELECT
[GroupBy1]。[A1] AS [C1]
FROM(
SELECT
COUNT(1)AS [A1]
FROM [dbo]。[__ MigrationHistory] AS [Extent1]
)AS [GroupBy1]
QUERY 2
错误:无效的对象名称'dbo.EdmMetadata'。
SELECT TOP (1)
[Extent1]。[Id] AS [Id],
[Extent1]。[ModelHash] AS [ModelHash]
FROM [dbo]。[EdmMetadata] AS [Extent1]
ORDER BY [E xtent1]。[Id] DESC
为什么?
我没有 dbo.EdmMetadata
和 dbo .__ MigrationHistory $ c $数据库中的c>表已经存在了。
如何解决这个问题?
dbo.EdmMetadata
和 dbo .__ MigrationHistory
哪个代码首先期待。要解决这个问题,您可以尝试将 SetInitializer
设置为null。 static NameOfYourContext()
{
Database.SetInitializer< NameOfYourContext>(null);
}
你可以在这篇文章的评论部分看到这个=http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx#7579835> Scott Gu
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?
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
这篇关于无效的对象名称“dbo.EdmMetadata”和“dbo .__ MigrationHistory”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!