Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Entity Framework question
Message
From
05/11/2009 14:17:35
 
 
To
05/11/2009 13:58:31
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01433374
Message ID:
01433396
Views:
47
>>I'm sure the answer to this must be simple but I'm still finding my way around the Entity Framework so....
>>
>>I load an EntityObject (User) together with a child EntityCollection (Roles). Subsequently I programatically remove one or more items from the collection.
>>
>>Given a reference to the EntityObject how do I reload the original EntityCollection?
>>
>>TIA,
>>Viv
>
>Hmm, I've never even built an EF model, so I'm just asking a curious question here... If, when you deleted the Item from the child collection, you were working against the collection that (I assume) is a linked property off of the parent Entity, why would it be necessary to "reload" the parent (and thereby the child collection, right)?

>
>Thinking about this kind of architecture from a classic object oriented paradigm, it seems like the parent's collection of child items would just always be up to date with respect to the in-memory state of the data model, as long as your work against THAT collection, not some other un-linked colelction of the same child objects.
>
>Notwithstanding the above (possibly stupid assumption), how did you initially populate the parent (and related child records)? Is there a call like User.Load(UserID)? If so, you'd need to be sure to "push" the delete on the child collection back to the real back-end data, then call the User.Load() method to pull back a fresh version of the parent and child records (after delete).

This is a 'Cancel' button type of operation. I've deleted one or more of the child items in the 'in memory' graph - but now I want to discard those changes and have the Entities go back to what was originally (or, for simplicities sake, currently) in the backend

In EF you can load the child collection as part of the query or 'lazy-load' later i.e.:
from x in Context.Users.Include("Roles") select x;
or subsequently:
User.Roles.Load();
IAE the end result is the same
>
>I'll be curious to find out how this all works. I've only used LinqToSql so far, so EF seems like a BIG MONSTER to me. Maybe it's not.

It's a *bit* of a monster (the O'Reilly book is 800 pages) :-{
Previous
Reply
Map
View

Click here to load this message in the networking platform