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

查看:54
本文介绍了如何使用Linq以类格式获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在课堂设计中获取数据

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; }

}

我正在使用以下代码获取
db是sqliteconntion字符串;

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>()
       );

C#4.0中的元组类型中查找linq示例

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

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

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

这篇关于如何使用Linq以类格式获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆