Create list instead of HashSet in constructor (EF6)

Posts   
 
    
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 25-Apr-2017 06:18:38   

The EF6 template creates a HashSet in the constructor. For certain collections I need an OrderedHashSet/List though. How could I customize this per relationship please?

public partial class Geo : CommonEntityBase
{
/// <summary>Initializes a new instance of the <see cref="Gevent"/> class.</summary>
public Geo() : base()
{
    this.ContentInfos = new HashSet<ContentInfo>();
}

Thanks Patrick

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Apr-2017 09:45:03   

Hi Patrick,

There is no setting for that. In this case you should write your own version of the template.

Could you please explain a elaborate on this need?

David Elizondo | LLBLGen Support Team
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 25-Apr-2017 17:47:45   

The use case is that we want the related entity collection to be sorted when it gets returned from the database. A HashSet doesn't keep the sort order.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 26-Apr-2017 02:20:23   

The use case is that we want the related entity collection to be sorted when it gets returned from the database. A HashSet doesn't keep the sort order.

Aren't entities sorted in the Collection's Entity view on one or more fields?

What's the use case of having them sorted inside the collection

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 26-Apr-2017 08:08:54   

EF6 (Entity Framework) doesn't have this view. So even though I'm sorting data in the related query I can't see that in the hashset

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 26-Apr-2017 10:30:51   

This is currently not supported. There's a partial method OnCreated in the CommonEntityBase but it's called from the ctor which is too early.

Frans Bouma | Lead developer LLBLGen Pro
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 26-Apr-2017 18:56:53   

Would you adding a call to a partial method in the ctor template so developers can add their own initialization? Then you could create a HashSet and a moment later I could overwrite it with a List before any data is added to it. Thanks! Patrick

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 28-Apr-2017 10:08:11   

pat wrote:

Would you adding a call to a partial method in the ctor template so developers can add their own initialization? Then you could create a HashSet and a moment later I could overwrite it with a List before any data is added to it. Thanks! Patrick

We'll add it to the things to add in the future.

Frans Bouma | Lead developer LLBLGen Pro