c# - Order of 1:n relation using virtual List<T> -
i use entity framework , mvc. need address list order address id. when encapsulate property sort entity framework doesn't fill address list. can do?
public class student { public int studentid { get; set; } public string name{ get; set; } public string surname{ get; set; } //i need address list order address id??? public virtual list<studentaddress> address { get; set; } } public class studentaddress { [key] public int addressid{ get; set; } public string address { get; set; } public string city { get; set; } }
relationships considered unordered per standard of relational modelling won't able , shouldn't rely on order, should apply ordering before presenting data. can select anonymous type ordered addresses like:
students.select(x => new { student = x, addresses = x.address.orderby(y => y.addressid)) })
and if worry code duplications can wrap separate method , reuse it.
Comments
Post a Comment