In the class for the entity you are trying to work with, change the type of the navigation property to ObservableCollection.
From this:
public Customer() { this.CustomerAddresses = new HashSet<CustomerAddress>(); } public virtual ICollection<CustomerAddress> CustomerAddresses { get; set; } }
For this:
public Customer() { this.CustomerAddresses = new ObservableCollection<CustomerAddress>(); } public virtual ICollection<CustomerAddress> CustomerAddresses { get; set; } }
Since this is automatically generated code, you will also need to change some rules in the code generation file. Try manually making these changes so that they work first and then make the changes. For me, I had to make the following changes to my .tt file
Add using System.Collections.ObjectModel by adding the line below that mentions this.
return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion()) ? string.Format( CultureInfo.InvariantCulture, "{0}using System;{1}" + "{2}", inHeader ? Environment.NewLine : "", includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "", includeCollections ? (Environment.NewLine + "using System.Collections.ObjectModel;") : "", inHeader ? "" : Environment.NewLine) : "";
And change your HastSet ad to Observable Collection
this.<#=code.Escape(navigationProperty)#> = new ObservableCollection<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>();
Also change ICollection to ObservableCollection
navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType,
The code generation file may differ from mine, but these parts of the code should give you an idea of what to look for in your file.
source share