如何使用LINQ以类格式获取数据[英] how to get data in the class format with the Linq

本文是小编为大家收集整理的关于如何使用LINQ以类格式获取数据的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

如何将数据作为我的类设计

获取数据
public class Fsr
{
    public string formId { get; set; }
    public string formName { get; set; }
    [PrimaryKey, AutoIncrement]
    public int fId { get; set; }
    public int resultId { get; set; }
}

public class Taskarray 
{        
    [PrimaryKey, AutoIncrement]
    public int taskId  {get ;set;}   
    public int resultId { get; set; }
}

public class  Result
{
    [PrimaryKey, AutoIncrement]
    public int resultId {get; set;}
    public List<Taskarray> taskarray { get; set; }
    public List<Fsr> fsr { get; set; }
    public int rootId { get; set; }

}

我正在使用以下代码获取
db是sqliteconntion string;

 var data1 = (from e in db.Table<Result>()
              from f in db.Table<Fsr>() where f.resultId == e.resultId 
              from t in db.Table<Taskarray>() where t.resultId == e.resultId 
              select new
              {
                  e,
                  e.taskarray=t,
                  e.fsr=f
              }).ToList();

请告诉我如何得到这个

推荐答案

更新:作为查询不重做列表,您只需使用特定类型而没有数组

 select new Tuple<Result, Taskarray, Fsr >
      (
           e,
           t,
           f
       );

如果您不想创建新类,可以使用元组

 select new Tuple<Result, List<Taskarray>, List<Fsr> >
      (
           e,
           t.ToList<Taskarray>(),
           f.ToList<Fsr>()
       );

c#4.0


您可以尝试这样的尝试,您可以创建新类,以处理即将到来的数据

select new Myobject 
{
      e= e,
      taskarray =t,
      fsr =f
}

本文地址:https://www.itbaoku.cn/post/1556889.html

问题描述

how can i get the data as my class design

public class Fsr
{
    public string formId { get; set; }
    public string formName { get; set; }
    [PrimaryKey, AutoIncrement]
    public int fId { get; set; }
    public int resultId { get; set; }
}

public class Taskarray 
{        
    [PrimaryKey, AutoIncrement]
    public int taskId  {get ;set;}   
    public int resultId { get; set; }
}

public class  Result
{
    [PrimaryKey, AutoIncrement]
    public int resultId {get; set;}
    public List<Taskarray> taskarray { get; set; }
    public List<Fsr> fsr { get; set; }
    public int rootId { get; set; }

}

I am using the below code to get
db is sqliteconntion string;

 var data1 = (from e in db.Table<Result>()
              from f in db.Table<Fsr>() where f.resultId == e.resultId 
              from t in db.Table<Taskarray>() where t.resultId == e.resultId 
              select new
              {
                  e,
                  e.taskarray=t,
                  e.fsr=f
              }).ToList();

please tell how i get this

推荐答案

Update : as query not reutrning list you can just use specific type without array

 select new Tuple<Result, Taskarray, Fsr >
      (
           e,
           t,
           f
       );

You can make use of tuple if you dont want to create new class fro mapping

 select new Tuple<Result, List<Taskarray>, List<Fsr> >
      (
           e,
           t.ToList<Taskarray>(),
           f.ToList<Fsr>()
       );

Find linq example at Tuple Type in C#4.0


you can try like this , you can create new class which handle the data coming

select new Myobject 
{
      e= e,
      taskarray =t,
      fsr =f
}
相关标签/搜索