2012-05-01 39 views
0

遇到問題;在同一個控制器中對同一個視圖使用兩個查詢。在使用相同的視圖相同的控制器使用兩個查詢 - User.Identity.Name

首先查詢

var results = from b in db.tbl_Rough 
        .Where(c => c.tbl_Assoc.Username == User.Identity.Name) 
        select b; 

第二個查詢

var results1 = from c in db.tbl_Rough 
        .Where(c => c.tbl_Cous.UserName == User.Identity.Name) 
         select c; 

以上兩種查詢的正常工作。我想要做的就是將他們結合起來,讓他們以相同的觀點工作。需要檢查兩個查詢以查看用戶是否有數據。

+2

出來你是什麼意思通過結合他們?要有一組結果? (即一個linq查詢) –

回答

2

我把你的

「兩個查詢需要進行檢查,看是否有用戶數據」

var resultAll = from all in db.tbl_Rough 
       .Where(c => c.tbl_Assoc.Username == User.Identify.Name && c.tbl_Cous.UserName == User.Identify.Name) 
       select all; 
+0

如果不是,它可能是'||'而不是'&&' – jessehouwing

相關問題