sql server 2008 - Sorting navigation properties in Entity Framework -


consider following database tables:

create table [dbo].[step] (    [stepid] int not null primary key identity,    [orderindex] int not null )  create table [dbo].[stepinput] (    [stepinputid] int not null primary key identity,     [stepid] int not null,     [orderindex] int not null,     constraint [fk_stepinput_step] foreign key ([stepid]) references [step]([stepid])  on delete cascade,  ) 

with following pocos:

public class step {    public virtual int stepid { get; set; }    public virtual icollection<stepinput> stepinputs { get; set; } }  public class stepinput {    public int stepinputid { get; set; }    public int stepid { get; set; }    public virtual int orderindex { get; set; } } 

i stepinputs ordered orderindex. there way setup navigation property sorted automatically ef, user of step not have call stepinputs.orderby every time?

i using database-first model.

edit: did realize add orderedinputs property step, returns stepinputs.orderby(...), solved immediate problem, though i'm not sure performance implications. still curious whether there way set in ef without having use custom property.

no way...! think have 2 tricks:

1) create static dbcontext, , first time, load data need memory using .load() , perform ordering, , use in-memory data in local property of dbctx.<dbset>s - ugly way , doesn't satisfy you...

2) create stored procedure retrieve data , perform ordering in database, , map sp entity in model.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -