MS实体框架如何从概念模型映射到CLR类型? [英] How does MS Entity Framework map from the conceptual model to CLR types?

查看:123
本文介绍了MS实体框架如何从概念模型映射到CLR类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定具有代码生成策略设置为无的实体数据模型(EDMX),EF如何确定将概念模型映射到哪个CLR类型?



我认为我在某处找到它只是针对与概念模型相匹配的类型来检测程序集,但这是参考EF的CTP版本。还是这样吗?
我可以控制这个过程吗?



特别是,我在一个场景中,我将使用Linq2SQL移植到使用POCO与EF 4.0的实质代码库。因此,我有Linq2SQL类和我的POCO类,现在居住在同一个程序集中,但是在不同的命名空间中。我正在尝试从L2S平滑迁移到EF,所以我想让这两个框架并行运行一段时间。但是,我收到一个运行时错误说


CLR类型到EDM类型的映射是
含糊,因为多个CLR类型
匹配EDM类型SomeType。
以前发现CLR类型
'SomeNamespace.SomeType',新找到
CLR类型'SomeNamespace.POCO.SomeType'


其中SomeNamespace是L2S实体的命名空间。如果EF只是探索与概念模型匹配的所有类型,这个错误是有道理的。我可以限制EF只能探测SomeNamespace.POCO命名空间吗?还是应该把我的POCO对象放在另一个程序集中?或者我应该采取第三种方法?



谢谢。

解决方案

请注意ADO.NET团队博客中的此评论:


Jeff 25 Feb 2010 9:10 AM @Derek



这是有意的。您可以将
POCO类放在您想要的任何命名空间
中。实体框架的
约定机制用于检测
实体上的属性匹配

模型中的实体的属性不使用命名空间。什么
重要的是类型名称(没有
命名空间)与模型中的EntityType名称
匹配(edmx / csdl文件)。



要注意的一个区域是,如果
有多个类型,名称相同的名称为
,但在不同的命名空间中。因为
我们不考虑命名空间,我们
检测到我们发现多个类型
,我们抛出一个异常。



Jeff


看到这篇文章:
链接文本


Given an Entity Data Model (EDMX) with "Code Generation Strategy" set to "None", how does EF determine which CLR types to map the conceptual model to?

I think I read somewhere that it just probes the assembly for types that match the conceptual model, but that was in reference to a CTP edition of EF. Is this still the case? Can I control this process somehow?

In particular, I am in a scenario where I am moving a substantial codebase from using Linq2SQL to using POCO with EF 4.0. Thus, I have the Linq2SQL classes as well as my POCO classes, for now residing in the same assembly, but in different namespaces. I'm trying to have a smooth migration from L2S to EF so I would like to have the two frameworks run in parallel for a while. However, I get a runtime-error saying

The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'SomeType'. Previously found CLR type 'SomeNamespace.SomeType', newly found CLR type 'SomeNamespace.POCO.SomeType'

where SomeNamespace is the namespace of the L2S entities. This error makes sense if EF is just probing for all types matching the conceptual model. Can I confine EF to only probe the SomeNamespace.POCO namespace? Or should I put my POCO objects in another assembly? Or should I take a third approach?

Thank you.

解决方案

Notice this comment from the ADO.NET team blog:

Jeff 25 Feb 2010 9:10 AM @Derek

This is intentional. You can put your POCO classes in whatever namespace you'd like. The Entity Framework's by convention mechanism for detecting which properties on the entity match the properties of entities in your model does not use Namespace. What matters is that the type name (without namespace) matches the EntityType name in your model (edmx/csdl file).

One area to watch out for is if you have multiple types with the same name but in different namespaces. Because we don't account for namespace, we detect that we've found multiple types and we throw an exception.

Jeff

See this article: link text

这篇关于MS实体框架如何从概念模型映射到CLR类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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