Home Dashboard Directory Help
Search

EntityCollection should implement the INotifyCollectionChanged interface by omjbe


Status: 

Closed
 as By Design Help for as By Design


15
0
Sign in
to vote
Type: Suggestion
ID: 507563
Opened: 11/2/2009 8:15:25 AM
Access Restriction: Public
1
Workaround(s)
view

Description

The EntityCollection supports the IListSource interface for WinForms data binding. However, it seems that WPF doesn't use this interface.

At the moment we have to use workarounds like synchronizing an ObservableCollection with the EntityCollection.
Details
Sign in to post a comment.
Posted by Microsoft on 11/4/2009 at 5:35 PM
Thanks again for your feedback. Implementing INotifyCollectionChanged on EntityCollection<T> is something that has been onour priority list along with many other improvements to the control data binding experience using Entity Framework classes. Unfortunately this support is not going to make it into Visual Studio 2010 and .NET 4.0, but we plan to revisit these requests for a future release.

Entity Framework Team
Posted by Microsoft on 11/3/2009 at 7:51 PM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by omjbe on 11/2/2009 at 8:38 AM
public class Menu : EntityObject {
...
private ObservableCollection<Helptask> helptaskList;

// Note: The Helptasks property is the generated EntityCollection

public IList<Helptask> HelptaskList
{
    get
    {
        if (helptaskList == null)
        {
            helptaskList = new ObservableCollection<Helptask>(Helptasks.ToList());
            helptaskList.CollectionChanged += HelptaskListCollectionChanged;
        }
        return helptaskList;
    }
}

private void HelptaskListCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    if (e.Action == NotifyCollectionChangedAction.Add)
    {
        foreach (Helptask helptask in e.NewItems)
        {
            Helptasks.Add(helptask);
        }
    }
    else if (e.Action == NotifyCollectionChangedAction.Remove)
    {
        foreach (Helptask helptask in e.OldItems)
        {
            Helptasks.Remove(helptask);
        }
    }
    else
    {
        throw new NotSupportedException();
    }
}