2014-02-06 17 views
1

我怎樣才能得到的數據作爲我的一流的設計如何獲得在類格式的數據與LINQ的

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

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

請告訴我如何得到這個

回答

1

更新:作爲查詢不reutrning列表,你可以只使用特定類型的無陣列

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

你可以,如果利用元組的你不想創建新的類映射

select new Tuple<Result, List<Taskarray>, List<Fsr> > 
     (
      e, 
      t.ToList<Taskarray>(), 
      f.ToList<Fsr>() 
     ); 
Tuple Type in C#4.0


你可以嘗試這樣的

查找LINQ例如,您可以創建一個處理未來

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

'Result'似乎對數據進行類映射到表中的新類,你無法投影到與表映射一起使用的實體。 – Habib

+0

你應該創建一個新的類而不是'Result',並將結果投影到這個類,我的觀點是,你當前的答案不會幫助OP,因爲'Result'被映射到DB實體 – Habib

+0

現在看起來好多了,移除了我的downvote – Habib

相關問題