c# - Linq join query displayed in MVC view -


i'm trying display linq join query in partial web view.

here query within controller:

public actionresult inactiveusers()         {             using (modelcontainer ctn = new modelcontainer())             {                 datetime duration = datetime.now.adddays(-3);                  var inactive = usrs in ctn.aspnet_users                                usrs.lastactivitydate <= duration                                join o in ctn.groups on                                usrs.userid equals o.userid                                select new                                {                                    usrs.username,                                    usrs.lastactivitydate,                                    o.primaryphonenumber,                                };                  return view(inactive.tolist());             }          } 

what i'm bit confused on next. i'm familiar adding typed views using models, happens in case have join query?

if point me in right direction i'd grateful.

thanks.

instead of returning ienumerable of anonymous types, create class join result , create model normal:

            var inactive = usrs in ctn.aspnet_users                            usrs.lastactivitydate <= duration                            join o in ctn.groups on                            usrs.userid equals o.userid                            select new inactiveuser(usrs.username, usrs.lastactivitydate, o.primaryphonenumber); 

with inactiveuser class has constructor takes username, date , phonenumber.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -