2012-05-01 112 views
-1

我想從一個表連接的結果,對2個不同的行從哪裏狀況總結的結果,因爲這樣的代碼:LINQ的 - 加入2列結果來自同一個表

 var a = (from o in _DB.Services 
       where (o.description.Contains(searchText) || o.nom.Contains(searchText)) 
       orderby o.date 
       select new { results = ?????, id = ?????? }).Take(maxResults).ToList(); 

能有什麼我說,爲了考慮到結果= ????和id = ???

謝謝

+0

你想檢索哪些列? – mattytommo

+0

您好Mattyommo,表格中的幾列,在我的情況下是2列(說明和標稱),但在某些情況下是3列 – dtjmsy

+0

如果描述或標記包含搜索文本,您希望選擇哪一個匹配?或者兩者無關?怎麼樣的ID?那也取決於比賽嗎? – mattytommo

回答

0

根據你的評論,你不能只是做下面的事情嗎?

var a = (from o in _DB.Services 
      where (o.description.Contains(searchText) || o.nom.Contains(searchText)) 
      orderby o.date 
      select new 
        { 
         results = o.description, 
         id = o.nom 
        }) 
      .Take(maxResults) 
      .ToList();