简体   繁体   English

为什么实体框架代码优先(使用现有数据库)继续尝试从EdmMetadata表获取数据?

[英]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.

相关问题 如何从实体数据向导以Entity Framework代码优先的方式导入现有存储过程? - How to import existing stored procedure in Entity Framework code-first from entity data wizard? 实体框架优先代码和现有数据库 - Entity Framework code-first and existing database 实体框架代码优先使用现有数据库时的好处 - Entity Framework Code-First Benefits when using existing database 在现有MySQL数据库上使用实体框架4.1 Code-First - Using entity framework 4.1 Code-First on existing MySQL database 将列添加到 C# 和实体框架代码中的表中,而不删除数据库内容 - Add column to table in C# & Entity Framework code-first without deleting DB content 首先更新Entity Framework 6中的现有实体 - Updating existing entities in Entity Framework 6 code-first 如何基于Entity Framework代码优先模型自动生成.mdf db(如果不存在) - How to automatically generate .mdf db if it does not exist based on Entity Framework code-first model 遵循Entity Framework代码优先方法,为什么不创建连接字符串? (未创建数据库) - Following Entity Framework code-first approach, why is connection string not created? (No DB created) 实体框架代码优先问题(SimpleMembership UserProfile表) - Entity Framework Code-First Issues (SimpleMembership UserProfile table) 实体框架代码优先在同一个表上的多对多关系 - Entity Framework Code-first Many to many relationship on the same table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM