8

I am calling a stored proc using SqlQuery, the result is supposed to be a graph of objects, i.e.

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, e.g. entities that contain properties of complex types.

3
  • This bug has been an irritant to me as well. Haven't found a workaround yet. Commented Mar 25, 2014 at 17:21
  • I would love to have this too Commented Apr 3, 2014 at 18:16
  • did you find any solution for this? Commented Aug 26, 2015 at 12:41

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.