如果这个问题已经被提出并得到回答,请原谅我。如果是这样,请指出我。我使用 VS2010 over .Net 3.5(平台更新不在我的控制范围内)和最新的 Service Pack。
我有一个存储过程,它将返回如下所示的行。没有其他列可以充当该实体的键;结果如下:
COUNTRYCODE QUANTITY
USA 100
UK 250
USA 300
USA 190
等等。
我按照 http://blogs.microsoft.co.il/blogs/gilf/archive/2009/03/13/mapping-stored-procedure-results-to-a-custom-entity-in-entity- Framework.aspx
以及 http://msdn.microsoft.com/en-us/library/cc982038(v=VS.90).aspx
这会导致错误“Entity Type soAndso has未定义键。定义此实体类型的键”
我们如何减轻此错误?我只是不需要这里的主键,并且无法修改存储过程。我要求 SOF 作为最后的手段。请帮忙。非常感谢。
Please forgive me if this question has been asked and answered already. If so, kindly point me to it. I'm using VS2010 over .Net 3.5 (platform update not in my control) with up-to-date Service Packs.
I have a stored proc that will return rows like the following. There is no other column that could function as a Key for this entity; the results look like this :
COUNTRYCODE QUANTITY
USA 100
UK 250
USA 300
USA 190
and so on.
I followed the steps from http://blogs.microsoft.co.il/blogs/gilf/archive/2009/03/13/mapping-stored-procedure-results-to-a-custom-entity-in-entity-framework.aspx
as well as http://msdn.microsoft.com/en-us/library/cc982038(v=VS.90).aspx
This keeps resulting in the error "Entity Type soAndso has no key defined. Define the Key for this Entity Type"
How do we mitigate this error? I just don't have a need for a primary key here and can't modify the stored procedure. I'm asking SOF as a last resort. Please help. Thank you very much.
发布评论
评论(1)
如果您不需要主键,那么我假设您不需要能够修改此数据并将其提交回服务器。在这种情况下,您应该使用复杂类型而不是实体类型。复杂类型是类,可以像实体一样充当 DTO,但不能将复杂类型用作基本插入/更新/删除对象。
编辑: 看起来复杂类型可能无法在 EFv1 (.NET 3.5) 中使用,除非作为对实体类型上的标量属性进行分组的方法。不幸的是,EFv1 远远不如 EFv4,并且可能根本无法解决涉及使用实体框架的问题。
If you don't have need for a primary key, then I'm assuming you don't have a requirement to be able to modify this data and submit it back to the server. In this case, you should use a Complex Type instead of an Entity type. Complex types are classes and can serve as DTO's just as well as entities can, but you can't use complex types as basic Insert/Update/Delete objects.
EDIT: It appears that complex types may not be usable in EFv1 (.NET 3.5) except as a means of grouping scalar properties on entity types. Unfortunately EFv1 is vastly inferior to EFv4 and there simply may not be a solution to your problem that involves using the Entity Framework.