I am having problems returning multiple objects (downloadable load) using the Include () method. I am trying to load entites in a silverlight application using RIA services. The data model consists of the following relationships:
Events.ID = EventParticipants.EventsID
EventParticipants.ParticipantUserID = Users.ID
Thus, an Event can have many participants, and a participant can have exactly 1 user.
I can load the event just fine, but I canβt get anything from the child relationships specified in the Include () statement.
When I load an Event, I try to use (using the download) all EventParticipants and their associated user records. In my domain service, I have the following:
public IQueryable<Event> GetEvents() { return this.ObjectContext.Events .Include("EventParticipants") .Include("EventParticipants.User"); }
Then I take the returned IQueryable and load it using my client-side domain context as follows:
DomainContext.Load(DomainContext.GetEventsQuery(), LoadOperationCompleted, true);
(usually I would filter it out, but I simplified everything to understand the essence of the problem)
In my LoadOperationCompleted, I have 2 loops that I use to check if Event participants are returned, but I never get a response from the participants. (I have 242 events defined in the database ... all of which have participants)
private void LoadOperationCompleted(LoadOperation lo) { if (lo.Error != null) { Debugger.Break(); lo.MarkErrorAsHandled(); } foreach (Event item in lo.Entities) { foreach (var particpant in item.EventParticipants) { Debug.WriteLine("{0} {1}", particpant.User.First, particpant.User.Last); } } }
I also modified the above code (see below) to scroll through the source domain context instead of the entity collection, which is passed through the parameters of the load operation to no avail. (there are events, no children)
foreach (Event item in DomainContext.Events)
My data model has three constructors (all generated) with different parameters. In each, I turned off lazy loading like this:
this.ContextOptions.LazyLoadingEnabled = false;
An annotation has appeared in the XML representation of DataModel.edmx. I think this is only for generation purposes ... but I also changed this:
<EntityContainer Name="MyCrazyEntities" annotation:LazyLoadingEnabled="false">
I defined the relationships in my SQL Server 2008 database. The designer picked them up and created all their relationships and navigation properties in my model. By checking them, they look valid. If I pushed the spelling of entities in an include statement, this will throw an error indicating that the path is invalid (or something like that) ... so I believe that relationships exist and are functional (and I can see their definitions in the code designer and something else).
I removed all filtering and, in particular, additional connections that I placed in the request before releasing it. This was to ensure that I did not encounter a problem when the connections change the request form and break Includes (). This seems to be a big problem for people, so I eliminated all the unions in such a way as to isolate the problem. This is not a combination of combinations and includes.
I rebuilt my projects in Silverlight, which hosted the domain service and the RIA Services DLL several times, thinking that my configuration was incorrect. I used a POCO class generator with EF, but then I read that you cannot enable the same path with POCOs ... so I also abandoned it and returned to the default entity generator.
I activated the SQL Server profiler and grabbed SQL from the base query, and the other with Includes (). Data for Includes RETURNS . I checked this by copying the request from the profiler and releasing it directly. A simplified version of the request is as follows. These relationships are valid, and I see that all the data associated with them is (for example, names of participants, phone numbers, etc.)
SELECT 'trimmed fields for brevity>' FROM ( SELECT 'trimmed fields for brevity>' CASE WHEN ([Join1].[ID1] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1] FROM [dbo].[Events] AS [Extent1] LEFT OUTER JOIN (SELECT 'trimmed fields for brevity>' FROM [dbo].[EventParticipants] AS [Extent2] INNER JOIN [dbo].[Users] AS [Extent3] ON [Extent2].[ParticipantUsersID] = [Extent3].[ID] ) AS [Join1] ON [Extent1].[ID] = [Join1].[EventsID] ) AS [Project1] ORDER BY [Project1].[ID] ASC, [Project1].[C1] ASC
However, when the object returns, Event.EventParticipants EntityCollection is empty. Unfortunately. Disappointingly. Painfully. (I'm from a Lee)
I browsed the Internet for solutions, but did not find anyone with the same problem that was not solved by the lazyloading parameter, a combination of connections and includes or inappropriate navigation properties.
Did I just miss some basic thing? Is there a fundamental concept that I am missing? I have another project from an old employer where they perform the same operation and seem to work. Therefore, I am sure that this can be done. Just not me?
Any help is appreciated. I am on my way. Thanks in advance!