Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何查看此自定义Linq查询?_C#_Linq - Fatal编程技术网

C# 如何查看此自定义Linq查询?

C# 如何查看此自定义Linq查询?,c#,linq,C#,Linq,我是Linq的新手,需要一些帮助。 我试图将自定义Linq查询设置为MVC视图,但我真的不知道如何设置 这是我的actionresult中的代码 从st到db.Stats orderby st.ID descending select new { st.ID, st.Date, st.Created, st.Accepted,

我是Linq的新手,需要一些帮助。 我试图将自定义Linq查询设置为MVC视图,但我真的不知道如何设置

这是我的actionresult中的代码

从st到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

我知道我应该使用viewmodel来实现这一点,但由于Totaltime和Ordertime是在查询中创建的,所以我一直停留在这两个方面。

您可以创建一个新的具体类,然后选择新的示例,而不是执行
选择新的

public class Example
{
    public string ID { get; set; }
    public string Filename { get; set; }
}
您可以使用LINQ获取的列表,例如:

List<Example> data = (from x in events
                      group x by x.GetMessageFields() into grouping
                      let y = grouping.Select(x => x.GetFilename()).ToList()
                      select new Example
                      {
                          ID = grouping.Key,
                          Filename = y.First()
                      }).ToList();

“但我被卡住了”:你怎么被卡住了?它在干什么?你想让它做什么?这是在一个新的列中取两个时间列和datediff它们之间的时间。用于totaltime和ordertime。
model.ExamplesList = data;