Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: Ensuring order of elements in a list [EF6]

$
0
0
Hi,

I'm writing an application using Entity Framework 6 code first.

I have a relationship where the order of the elements must be modifiable by the user and must always be retrieved in the same way. When working with NHibernate, one can configure the "type" of relationship when doing a "On to many" and select whether it's a "Set", "Bag", "List", etc.

Is there something similar in EF?

As an example, let's say I have this kind of classes:
publicclass ReadProcess
{
    publicint Id {get; set;}

    publicstring Name {get; set;}
    
    public ICollection<ReadCommand> ReadCommands {get; set;}
}

publicclass Command : ICommand
{
    publicint Id {get; set;}
    
    publicstring FileName {get; set;}
    
    publicvoid Execute()
    {
        ...
    }
}
How do I tell EF that the order of the "ReadCommands" is important and should be saved?

I did a small test and when I do
MyReadProcess.ReadCommands.Insert(0, testCommand);
And then save the MyReadProcess, the testCommand is correctly saved, but not keeping the order.

Thanks.

Viewing all articles
Browse latest Browse all 1793