Mapping Complex Types to results form SqlQuery in Entity Framework
I am calling a stored proc using SqlQuery, the result is supposed to be a graph of objects, ie
public class Person
{
public int Id{get;set;}
public string FullName {get;set;}
public Address HomeAddress {get;set;}
public Vehicle PrivateVehicle {get;set;}
}
But SqlQuery wont map the Address and Vehicle. It only maps the column names to the properties.
Is there a work around this? How else can I do the mapping?
I found this:
.. what you can't do is return graphs of objects, eg entities that contain properties of complex types.
Entity Framework (up through 6 anyway) doesn't support mapping raw SqlQueries to an object graph, only as a simple entity.
You can use standard LINQ with standard Entity Framework reference mapping between them, and use Includes or whatever else you need.
But if standard LINQ to EF won't work because your SqlQuery uses SQL functions or stored procedures or something, then you're out of luck.
PS: Posting your SQL query might help in the future so the answer can be more specific to your problem.
链接地址: http://www.djcxy.com/p/18296.html