linq to entities - Entity Framework - Issue returning Relationship Entity -


ok, must working hard because can't head around takes use entity framework correctly.

here trying do:

i have 2 tables: headertable , detailtable. detailtable have 1 many records each row in headertable. in edm set relationship between these 2 tables reflect this.

since there relationship setup between these tables, thought quering records in headertable, able access detailtable collection created edm (i can see property when quering, it's null).

here query (this silverlight app, using domaincontext on client):

 // mycontext instatiated class scope   entityquery<project> query = _mycontext.getheadersquery();     _mycontext.load<project>(query);    

since these calls asynchronous, check values after callback has completed. when checking value of _mycontext.headertable have rows expected. however, detailstable property within _mycontext.headertable empty.

foreach (var h in _mycontext.headertable)  // has records     {       foreach (var d in h.detailtable)  // no records       {         string test = d.description;       } 

i'm assuming query return headertable objects needs modified somehow return headerdetail collectoins each headertable row. don't understand how non-logical modeling stuff works yet.

what doing wrong? appriciated. if need more information, let me know. happy provide need.

thanks,

-scott

what you're missing include(), think out of scope of code provided.

check out cool video; explained edm , linq-to-entities me:
http://msdn.microsoft.com/en-us/data/ff628210.aspx

in case can't view video now, check out piece of code have based on videos (sorry it's not in silverlight, it's same basic idea, hope).

the retrieval:

public list<story> getallstories() {     return context.stories.include("user").include("storycomments").where(s => s.hostid == currenthost.id).tolist(); } 

loading the data:

private void loadallstories() {     lvwstories.datasource = tecontext.getallstories();     lvwstories.databind(); } 

using data:

protected void lvwstories_itemdatabound(object sender, listviewitemeventargs e) {     if (e.item.itemtype == listviewitemtype.dataitem)     {         story story = e.item.dataitem story;          //  blah blah blah....          hlstory.text = story.title;         hlstory.navigateurl = "storyview.aspx?id=" + story.id;         lblstorycommentcount.text = "(" + story.storycomments.count.tostring() + " comment" + (story.storycomments.count > 1 ? "s" : "") + ")";         lblstorybody.text = story.body;         lblstoryuser.text = story.user.username;         lblstorydts.text = story.addeddts.toshorttimestring();     }             } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -