[英]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 :- 我正在尝试对现有数据库执行一些实体框架代码优先编程..但我一直在我的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? 这个EdmMetadata表到底是什么?为什么我的EF代码试图从那里获取Id和ModelHash?
Remember, I'm trying to work against an existing DB. 请记住,我正在尝试对抗现有数据库。
Cheers :) 干杯:)
There is no Code-First against existing database. 针对现有数据库没有Code-First。 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. EdmMetadata表保留当前代码优先模型的哈希值,它允许DbContext
检测模型的更改,以便可以重新创建数据库。 This feature is turned on by default. 默认情况下,此功能处于启用状态。 You can turn it off by removing convention in OnModelCreating
: 您可以通过删除OnModelCreating
约定来关闭它:
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.