(1) Can someone please explain the difference between performing data access using the two different methods described below?
context.Refresh(RefreshMode.ClientWins, context.ParentEntity);
and
return (from pe in context.ParentEntity select pe).ToList();
(2) And for a more complicated example with child entities/navigation properties involved, are there any fundamental differences between these two calls:
context.Refresh(RefreshMode.ClientWins, context.ParentEntity);
context.Refresh(RefreshMode.ClientWins, context.ChildEntity);
and
return (from pe in context.ParentEntity.Include("ChildEntities") select pe).ToList();
(3) Finally, we have some code that performs a combination of the two methods:
context.Refresh(RefreshMode.ClientWins, context.ParentEntity.Include("ChildEntities"))
I’m trying to get my head wrapped around when one method should be used over another or if they are all functionally equivalent.
I think you have the wrong ideas about
RefreshandInclude…“
Refreshhas the dual purpose of allowing an object to be refreshed with data from the data source and being the mechanism by which conflicts can be resolved” (from MSDN)“
Includespecifies the related objects to include in the query results.” (from MSDN)So to answer your question,
Refreshis a void method and NOT a query… It is used to manage concurrency and resolve conflicts… I’m not sure if you were trying to get results back from this, but I can’t imagine it worked very well!Your
(from pe in context...statements are LINQ queries making use of theIncludemethod, which (like it sounds) includes the specified objects in the query results.Taking a look at the MSDN pages for the methods can usually help quite a bit when you’re not sure what they are doing.
Hope this helped!