c# - How can i put this custom Linq query to view? -


i'm kind of newbie on linq , use help. i'm trying set custom linq query mvc view can't figure out how to?

here code actionresult

from st in db.stats

        orderby             st.id descending         select new          {             st.id,             st.date,             st.created,             st.accepted,             st.ended,             totaltime =                 (sqlfunctions.stringconvert((double) sqlfunctions.datediff("ss", st.created, st.ended)/60) + ":" +                  ("0" + sqlfunctions.stringconvert((double) sqlfunctions.datediff("ss", st.created, st.ended)%60))                      .substring(                          ("0" +                           sqlfunctions.stringconvert((double) sqlfunctions.datediff("ss", st.created, st.ended)%60))                              .length - 2, 2)),             ordertime =                 (sqlfunctions.stringconvert((double) sqlfunctions.datediff("ss", st.accepted, st.ended)/60) +                  ":" +                  ("0" +                   sqlfunctions.stringconvert((double) sqlfunctions.datediff("ss", st.accepted, st.ended)%60))                      .substring(                          ("0" +                           sqlfunctions.stringconvert(                               (double) sqlfunctions.datediff("ss", st.accepted, st.ended)%60)).length - 2, 2)),             st.message 

i know should use viewmodel right i'm stuck on totaltime , ordertime since created in query.

instead of doing select new, can create new concrete class , select new example:

public class example {     public string id { get; set; }     public string filename { get; set; } } 

which can use linq fetch list of example:

list<example> data = (from x in events                       group x x.getmessagefields() grouping                       let y = grouping.select(x => x.getfilename()).tolist()                       select new example                       {                           id = grouping.key,                           filename = y.first()                       }).tolist(); 

if have model class, can add list<example> , use it:

model.exampleslist = data; 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -