你能在同一个项目中拥有数据库优先和代码吗? [英] Can you have database first and code first in the same project?

查看:116
本文介绍了你能在同一个项目中拥有数据库优先和代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个首先使用数据库的项目。

I have a project that was using database first.

我已经使用了我的一个实体集(一个edmx文件?)并将其转换为使用代码优先方法。

I have taken one of my entitysets (an edmx file?) and converted that to using code first approach.

我有一个简单的单元测试,它创建我的派生数据库上下文并尝试保存/重新水化代码第一个实体,但DbSet.Add最终抛出一个参数异常,说它无法找到概念另一个不相关的
和未使用的edmx文件中定义的类型的模型。

I have a simple unit test that creates my derived db context and tries to save / rehydrate the code first entity but DbSet.Add winds up throwing an argument exception saying that it could not find the conceptual model for a type defined in another unrelated and unused edmx file.

System.Data.Metadata.Edm.MetadataWorkspace.GetEdmSpaceType (StructuralType objectSpaceType)

System.Data.Metadata.Edm.MetadataWorkspace.GetEdmSpaceType(StructuralType objectSpaceType)

System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappings()

System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappings()

System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType (类型entityType)

System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType(Type entityType)

System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType)

System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType)

System.Data.Entity.Internal.InternalContext .GetEntitySetAndBaseTypeForType(Type entityType)

System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)

System.Data。 Entity.Internal.Linq.InternalSet`1.Initialize()

System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()

System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()

System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()

System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action,EntityState newState,Object entity,String methodName)

System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)

System.Data.Entity.Internal.Linq .InternalSet`1.Add(Object entity)

System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)

System.Data.Entity.DbSet`1.Add(TEntity entity)

System.Data.Entity.DbSet`1.Add(TEntity entity)

 


推荐答案

如果你是使用EDMX文件的默认代码生成,生成的类包含一系列属性,以帮助EF查找每个实体类型使用哪个类。 EF目前有一个限制,即无法从包含具有EF属性的类的程序集
加载POCO类。 (简短的回答是否定的,你的课程需要在不同的项目中)。

If you are using the default code generation for the EDMX file then the generated classes contain a series of attributes to help EF find which class to use for each entity type. EF currently has a restriction that POCO classes can't be loaded from an assembly that contains classes with the EF attributes. (Short answer is no, your classes need to be in separate projects).

这是一个有点人为的限制,我们意识到这是一件很痛苦的事情,并会尝试删除未来。

This is a somewhat artificial restriction and something that we realize is painful and will try and remove in the future.

〜罗文


这篇关于你能在同一个项目中拥有数据库优先和代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆