c# - Should i instantiate a new model? -


mvc. passing data view in model. in repository map linq result model. in controller send data. 1 should do:

list<personmodel> people = new list<personmodel>(); people = repo.getpersonlist(); return view(people); 

or

list<personmodel> people = repo.getpersonlist(); return view(people); 

as mentioned, in repo map result model, new model instance:

var query = p in _db.person                      orderby f.lastname                      select new personmodel                      {                          id = f.personid,                          lastname = f.lastname                      }; return query.tolist(); 

either 1 works. use second 1 because thinking, repo creating new model passing controller when call repo.getpersonlist function. should create new instance in controller well, or continue am?

go second.

your first snippet has redundant new list<t> call allocates new list, while next line overrides reference newly created list repo. absolutely no need that.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -