mercredi 22 avril 2020

Best practice for populating big ViewModel that Depends on multiple tables

enter image description hereWhat is best way to make least number of database fetches and populating view model that approximately every field depend and another table fetch for example

public class FirstClass { public int id{get;set;} public string name{get;set;}} 

and ViewModel depends on name property of FirstClass

public Class FirstViewModel{public string FirstClassName{get;set;}}

so I have to do this in my mind but I know there have to be better way

DBSet<FirstClass> FirstClass{get;set;}

controller or repository:

db.FirstClass.Find(x=>x.id == id).select(x=>x.name);

which is very awful for performance database wise.

Aucun commentaire:

Enregistrer un commentaire