RIA - Parent Entities

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
RobIntechnica
Posts: 33
Joined: Tue 09 Feb 2010 11:42
Location: Manchester, UK

RIA - Parent Entities

Post by RobIntechnica » Fri 19 Feb 2010 11:05

Hi

I'm using dotConnect with RIA to enable my Silverlight application to access my Oracle database.

On the client side, to get parent entities to load with the query that retrieves the child I have found I have to do the following to get things working.

In my child metadata class, use the include attribute:-

Code: Select all

[MetadataTypeAttribute(typeof(FOCUS_POINT.FOCUS_POINTMetadata))]
    public partial class FOCUS_POINT
    {

        internal sealed class FOCUS_POINTMetadata
        {

          [Include]
          public ANSWER_TYPES ANSWER_TYPES;

          ...
In my Domain Service class, iterate through the collection to load the parent(s):-

Code: Select all

public IQueryable GetFOCUS_POINTForHeaderVersion(int headerVersion)
        {

            var res = this.ObjectContext.FOCUS_POINT.Where(fp =>
                fp.FOCUS_P_HD_VER.FOCUS_P_HD_VER_ID == headerVersion).OrderBy(fp => fp.SORT_ORDER);


        


            foreach (var item in res)
            {
                
                item.ANSWER_TYPESReference.Load();

            }

            return res;
        }
Then this works in my Silverlight client:-

Code: Select all

    var loader3 = domainContext.Load(domainContext.GetFOCUS_POINTForHeaderVersionQuery(headerVersionId), false);

                    loader3.Completed += new EventHandler(loader3_Completed);

}

void loader3_Completed(object sender, EventArgs e)
{

foreach (var currentFocusPoint in domainContext.FOCUS_POINTs)
            {
                                
                

                MessageBox.Show(currentFocusPoint.ANSWER_TYPES == null ? "NULL" : "OK");


            }

}

Above code shows "OK".

Now I was wondering if there was a way without iterating through calling Load on each entity that is to be returned?

I read that you could use the Include method for LINQ to Entities as per this link:-

http://social.msdn.microsoft.com/Forums ... d163481f53

Trying this shows "NULL" in the above MessageBox code though. Thanks very much for your help in advance!

RobIntechnica
Posts: 33
Joined: Tue 09 Feb 2010 11:42
Location: Manchester, UK

Post by RobIntechnica » Fri 19 Feb 2010 17:07

Ah solved now. I wasn't using the Include method correctly!

cjaskoll
Posts: 1
Joined: Wed 12 May 2010 18:33

Post by cjaskoll » Wed 12 May 2010 18:39

RobIntechnica wrote:Ah solved now. I wasn't using the Include method correctly!
can you explain?

KW
Posts: 135
Joined: Tue 19 Feb 2008 19:12

Post by KW » Wed 12 May 2010 20:58

cjaskoll wrote:
RobIntechnica wrote:Ah solved now. I wasn't using the Include method correctly!
can you explain?
To use Include child records, you need to use the Include key word in the meta data that is generated for the domain class.

Then you need to use the Include keyword when you query in the domain service, for example:
var query = from c in this.objectcontext.Parent.Include("ChildRelatinoship") select c;

return query;

Post Reply