[英]Entity Framework v4 -> need some help with POCO's and Entities
I'm using EF4 and I've got two entities that I wish to map to the same POCO
. 我正在使用EF4,我有两个实体,我希望映射到同一个
POCO
。 I'm not sure how I can do this. 我不知道怎么能这样做。
Entity 1 → Foo (this represents a table FOO in the db)
实体1→Foo(这表示数据库中的表FOO)
POCO → FooPOCO→Foo
Entity 2 → FooView (this represents a view FooView in the db)
实体2→FooView(这表示数据库中的FooView视图)
POCO → FooPOCO→Foo
I understand that I need to do something like 我明白我需要做点什么
IObjectSet<Foo> _foos = CreateObjectSet<Foo>();
// Note spelling of the Entity.
IObjectSet<Foo> _foosView = CreateObjectSet<Foo>("FooViews");
But when i try this, it does compile, but it fails with the following exception: 但是当我尝试这个时,它确实编译,但它失败并出现以下异常:
System.ArgumentException: System.ArgumentException: The specified entity type, 'MyProject.Core.Foo', does not match the type 'EntityFramework.SqlServerModel.FoosView' from the EntitySet 'FoosViews'.
System.ArgumentException:System.ArgumentException:指定的实体类型“MyProject.Core.Foo”与EntitySet“FoosViews”中的“EntityFramework.SqlServerModel.FoosView”类型不匹配。
Any suggestions? 有什么建议?
Here is a checklist of things to look for: 以下是要查找的事项清单:
EntitySets
: Foo
and FooView
EntitySets
: Foo
和FooView
EntityTypes
: Foo
and FooView
EntityTypes
: Foo
和FooView
EntitySets
: Foo
and FooView
- both with an EntityType
set to ModelName.Foo
EntitySets
: Foo
和FooView
- 两者的EntityType
设置为ModelName.Foo
EntityType
: Foo
EntityType
: Foo
EntitySetMappings
: EntitySetMappings
:
Foo
with one EntityTypeMapping
("ModelName.Foo") with one MappingFragment
("Foo") Foo
与一个EntityTypeMapping
(“ModelName.Foo”)与一个MappingFragment
(“Foo”) FooView
with one EntityTypeMapping
("ModelName. Foo ") with one MappingFragment
("FooView") FooView
与一个EntityTypeMapping
( “MODELNAME。 富 ”)与一种MappingFragment
(“ FooView”) You should new be able to execute the following: 你应该新的能够执行以下内容:
Foo foo = new ModelEntities()
.CreateObjectSet<Foo>("FooView")
.First();
You can give yourself a headstart by doing the following: 您可以通过执行以下操作为自己做一个开始:
Foo
and FooView
to your model Foo
和FooView
添加到您的模型中 Mapping Details
of Foo
click Add a Table or View
and select FooView
Foo
的Mapping Details
,单击Add a Table or View
并选择FooView
FooView
from your model FooView
<EntityType Name="FooView">
in <StorageModels>
and remove any incorrect entries from <Key>
(it should match <EntityType Name="Foo">
) <StorageModels>
找到<EntityType Name="FooView">
并从<Key>
删除任何不正确的条目(它应匹配<EntityType Name="Foo">
) <EntityTypeMapping Name="IsTypeOf(Foo)" />
and <EntityTypeMapping Name="IsTypeOf(FooView)" />
(they caused me errors) <EntityTypeMapping Name="IsTypeOf(Foo)" />
和<EntityTypeMapping Name="IsTypeOf(FooView)" />
(它们导致我的错误) As of beta 2, implementing the above will break the designer 从beta 2开始,实现上述功能将打破设计师的角色
In NHibernate, one should solve this using Projections. 在NHibernate中,应该使用Projections来解决这个问题。 So, I think that there must exists something similar like that in the Entity Framework.
所以,我认为必须存在与实体框架类似的东西。 I've googled a bit, and I came accross this:
我用Google搜索了一下,然后我就来了:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.