none
INotifyCollectionChanged in Entity Framework 4.0 ?

Answers

  • Hello Lisa,

    EntityCollection<T> currently does not implement INotifyCollectionChanged, which is the “new” standard interface for notifying collection changes. However, the binding list that you can obtain for EntityCollection<T> (and which databinding will typically get when you pass and EntityCollection<T> as a data source) is an IBindingList which has its own “old” standard way of notifying of collection changes (namely, the ListChanged event). In general, WinForms and WPF databinding knows how to deal with this interface.

    Moreover, an EntityCollection<T> and its binding list are always synchronized both ways for both deletions and additions. The assertions you quoted from my blog refer to binding lists for ObjectQuery<T> and ObjectResult<T>, which are different from the binding list of an EntityCollection<T>.

    Please, let me know if you find any issues.

    Thanks,
    Diego


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Sunday, December 27, 2009 6:15 AM
    Moderator
  • Well poco objects dont have Load method on reference and collection properties so how else can u lazily load objects?

    Well for collection properties u can still get away if u are returning ICollection. You can can assign it to dynamic variable and call load.

    dynamic cust = customer;
    cust.Orders.Load();


    Zeeshan
    Wednesday, January 06, 2010 5:31 AM

All replies

  • Hello Lisa,

    EntityCollection<T> currently does not implement INotifyCollectionChanged, which is the “new” standard interface for notifying collection changes. However, the binding list that you can obtain for EntityCollection<T> (and which databinding will typically get when you pass and EntityCollection<T> as a data source) is an IBindingList which has its own “old” standard way of notifying of collection changes (namely, the ListChanged event). In general, WinForms and WPF databinding knows how to deal with this interface.

    Moreover, an EntityCollection<T> and its binding list are always synchronized both ways for both deletions and additions. The assertions you quoted from my blog refer to binding lists for ObjectQuery<T> and ObjectResult<T>, which are different from the binding list of an EntityCollection<T>.

    Please, let me know if you find any issues.

    Thanks,
    Diego


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Sunday, December 27, 2009 6:15 AM
    Moderator
  • http://666kb.com/i/bfgcsz56zmqbclmyp.gif

    see that image I am adding a pupil to a Pupils EntityCollection -> its updated in the GUI right after FINE!

    but... adding a new schoolclass entity to the context -> no update in the GUI

    I do not want to add the new schooclass in the View/Form like bindingSourceSchoolclass.Add(new Schoolclass());

    because that way the Model is leaked into the VIEW which is a No Go. Any solution to this?

    BindableLinq does not help either because it does not support ObjectResult queries.
    Friday, January 01, 2010 12:30 PM
  • You may want to try STE entities on the server side. The collection navigation property returns TrackableCollection which derives from ObservableCollection. Thus you get the following benefits.

    1. You receive notification when the collection is modified. This notification is used for change tracking and UIS like WPF can also use it to update their User interface.
    2. Like EntityCollection you also get relationship fixup when you modify a relationship using one end. For instance customer.Orders.Add(order1) would also set the order1.customer to the appropriate customer.

    STE comes with its own draw back like no support for lazy loading and use of snap shot based change tracking, but then you can use STE with the same context from which it was retrieved as long as u use it as POCO and not as STE but then you can use as disconnected by truly leveraging STE by calling ApplyChanges. If you use the later approach, remember to enable change tracking and also begin change tracking by using StartTracking and StopTracking.

    Zeeshan
    Monday, January 04, 2010 11:36 PM
  • I need lazy loading and eager loading for different UI areas. Do you mean StoredProcedure Entities with STE ?

    I am still thinking and fighting with myself to switch to WPF instead of Windows Forms, then my problem would be solved anyway. Wee will see...

    and about your book thats my secret ;P
    Tuesday, January 05, 2010 6:14 PM
  • Well you can sort of get lazy loading to work like using LoadProperty method. for instance to load orders for the customer i would do

    db.LoadProperty(Customer,"Orders")

    STE stands for Self Tracking Entity.

    By the way u got me curious. I don't know think i know u..
    Tuesday, January 05, 2010 6:44 PM
  • never heard of LoadProperty(...); to load related data I always used .Include(..);

    ah I see its only with EF 4 and Poco ->
    context.LoadProperty(Customer, o => o.Orders);
    Tuesday, January 05, 2010 7:00 PM
  • Lisa,

    Yes, LoadProperty is new in 4.0. It is basically a new way of doing the same thing as EntityCollection<T>.Load or EntityReference<T>.Load, but it works with all sorts of entities (not only POCO).

    Thanks,
    Diego
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, January 05, 2010 10:19 PM
    Moderator
  • Why was there the need to introduce .Load when there .Include? What are the advantages?
    Tuesday, January 05, 2010 11:58 PM
  • Well poco objects dont have Load method on reference and collection properties so how else can u lazily load objects?

    Well for collection properties u can still get away if u are returning ICollection. You can can assign it to dynamic variable and call load.

    dynamic cust = customer;
    cust.Orders.Load();


    Zeeshan
    Wednesday, January 06, 2010 5:31 AM