c# - Returning multiple related entity types from raw SQL queries in Entity Framework -


noodling around raw sql queries in entity framework. right in thinking given these 2 related ef classes:

public partial class campaign {     public int campaignid { get; set; }      public virtual icollection<quote> quotes { get; set; } }  public partial class quote {     public int quoteid { get; set; }     public int campaignid { get; set; }      public virtual campaign campaign { get; set; } } 

the tables joined foreign key, , objects generated db first entity framework.

i can't issue raw query campaigns , related quotes? i've tried this:

string sqlquery = "select * campaign c join quote q on q.campaignid = c.campaignid"; var meh = entities.database.sqlquery<campaign>(sqlquery); 

which brings campaigns without quotes. i'm guessing it's not feasible wanted check i'm not doing wrong?

i couldn't find definitive answer in documentation. , older related question fetching complex objects raw sql query in entity framework has upvotes no answers.

people have suggested duplicate of ef5 db.database.sqlquery mapping returned objects there's 1 difference: need related, nested entities rather complex type. effectively, want use sqlquery return identical result set to

entities.campaigns.include(c => c.quotes); 

(if want know why it's because have more complex set of includes returning large amounts of unasked data. no-one seems able explain why happening, i'm casting round alternative approaches)

i dont think can raw sql query. trying achieve nested realtionship model ef provides model mappings raw sql query provide same flat result running sql query on database. killing entity framework relational modeling concept , want same result ef provides relational mapping mechanism


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -