0
votes

When using Entity to build objects from database tables, one to many relationships are stored as collections within the 'one' object, the default property is of the type ICollection.

However, at run-time the object is instantiated as a HashSet.

Is there any way to configure entity to make the property a HashSet by default?

Currently I'm trying to return entity objects from an asmx web service however an ICollection can't be serialized due to it being an interface. I can get around this by changing all references to ICollection to a HashSet within the class code, however this is overwritten any time I make a change to the entity model.

1

1 Answers

0
votes

To change this, change the line: navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType,

within the Model.tt file to

navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("HashSet<" + endType + ">") : endType,