简体   繁体   English

实体框架 - 存储过程结果作为没有主键的实体

[英]Entity Framework - Stored Procedure result as an entity without Primary Key

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.我正在使用带有最新服务包的 VS2010 over.Net 3.5(平台更新不在我的控制范围内)。

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;没有其他列可以将 function 作为该实体的键; 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我按照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以及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 "这一直导致错误“实体类型 soAndso 没有定义键。定义此实体类型的键

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.我要求 SOF 作为最后的手段。 Please help.请帮忙。 Thank you very much.非常感谢。

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.复杂类型是类,可以像实体一样用作 DTO,但您不能将复杂类型用作基本的插入/更新/删除对象。

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.编辑:似乎复杂类型可能无法在 EFv1 (.NET 3.5) 中使用,除非作为对实体类型的标量属性进行分组的一种方式。 Unfortunately EFv1 is vastly inferior to EFv4 and there simply may not be a solution to your problem that involves using the Entity Framework.不幸的是,EFv1 远不如 EFv4,而且可能根本无法解决涉及使用实体框架的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM