Where is the best place to call the .tolist(); inside my controller classes or inside my model repository classes

Posted by john G on Stack Overflow See other posts from Stack Overflow or by john G
Published on 2013-11-13T09:46:00Z Indexed on 2013/11/13 9:53 UTC
Read the original article Hit count: 219

I have the following action method, inside my asp.net mvc web application:-

public JsonResult LoadZoneByDataCenter(string id)
        {
            var zonelist = repository.getrealtedzone(Convert.ToInt32(id)).ToList();
//code goes here

Which calls the following model repository method:-

 public IQueryable<Zone> getrealtedzone(int? dcid) {

         return   tms.Zones.Where(a=> a.DataCenterID == dcid || dcid == null);
        }

Currently I am calling the .tolist() which will interpret the Database from my action method, but my question is where is the best place to call the .tolist() inside the controller or inside the model classes and why ?

thanks

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about LINQ