Something I ran into using the Ajax.dll and AjaxMethods (Or basically the idea of being able to call a method from .cs file in javascript) is that when returning a list of Users there was difficulty in serialization. Basically, if you have a list of users that contain a list of roles that contain a list of permissions that contain seven wives with seven children with seven dogs and seven cats… Basically a lot of information. Now lazy loading should take care of this, but lets assume there is no lazy loading.(No idea what would cause that…) Well you have an awful lot to pushout to the front end. Let’s just say it can be a little sluggish. Lets assume you are just sending the list out, and you’ve already done all the querying.
You could do:
return userList;
Which is what I was doing. Kind of slow.
You could do:
var query = from user in userList select new { UserName = user.UserName, UserID = user.ID }; return query.ToList();
Nothing wrong with that, just a bit verbose for something so simple.
You could do this:
return userList.Select(currentItem => new { Username = currentItem.UserName, UserID = user.ID });
All in one line. Now I personally like the sql-ish linq expressions, but for this why not fit it into one line?