简体   繁体   中英

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. I've imported the stored procedure into my Entity Framework model and created a new complex type to store the results.

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? This would allow me to say something like, result.User.EmailAddress , even though the email address is not returned by my stored procedure? 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.

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.

AssociationAttribute is not used by Entity framework at all. It is used in WCF RIA Services.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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