简体   繁体   English

是否可以将存储过程列映射回EF4中的实体?

[英]Is it possible to map a stored procedure column back to an entity in EF4?

I have a stored procedure in my database that returns a set of data for some users. 我的数据库中有一个存储过程,该过程为某些用户返回一组数据。 Naturally, the userId is returned as part of this set. 自然,userId作为此集合的一部分返回。 I've imported the stored procedure into my Entity Framework model and created a new complex type to store the results. 我已将存储过程导入到我的Entity Framework模型中,并创建了一个新的复杂类型来存储结果。

List<GetUserData_Result> x = context.GetUserData().ToList();
List<int> userids = x.Select(u => u.UserId);

Is there any way to associate the userId in my complex type with the User entity that already exists? 有什么方法可以将我的复杂类型中的userId与已经存在的User实体相关联? This would allow me to say something like, result.User.EmailAddress , even though the email address is not returned by my stored procedure? 即使我的存储过程未返回电子邮件地址,这也可以使我说出诸如result.User.EmailAddress之类的内容? A lot of poking at MSDN indicates that this might be possible using the AssociationAttribute class, but I have so far been unable to find an example. 在MSDN上进行的大量戳戳表明,使用AssociationAttribute类可以实现此目的,但是到目前为止,我还没有找到一个示例。

It would be nice feature but current version doesn't offer this. 这将是一个不错的功能,但当前版本不提供此功能。 Complex type cannot have navigation properties (so it cannot point to entity). 复杂类型不能具有导航属性(因此它不能指向实体)。 That mean that EF will not do that for you but you can have your own property which will somehow get the user with that Id and return it - most probably this will make your complex type dependent on ObjectContext which is not good. 这意味着EF将不会为您执行此操作,但是您可以拥有自己的属性,该属性将以某种方式使用户获得该ID并返回它-最有可能的原因是,这会使您的复杂类型依赖于ObjectContext ,这是不好的。

AssociationAttribute is not used by Entity framework at all. 实体框架完全不使用AssociationAttribute It is used in WCF RIA Services. 它在WCF RIA服务中使用。

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

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