2016-07-28 17 views
0

該查詢返回door_id所有標籤匹配的門ID。將所有匹配的Llinq查詢轉換爲OR(至少一個標籤需要匹配)

List<decimal> matchingDoors db.tags 
    .Where(x => x.user_id == userId && (null == SystemId|| x.syid == SystemId)) 
    .GroupBy(x => x.door_id)   
    .Where(x => tags.All(y => 
      x.Any(z => z.name == y))) 
    .Select(x => x.Key).ToList<decimal>(); 

如何更改查詢以返回匹配至少一個標記('OR')的結果?

+0

@a_horse_with_no_name檢查了這一點。 –

+0

它只返回兩個匹配的人。 –

+0

錯誤的查詢,更新問題 –

回答

1

您應該在tags集合上使用Contains()方法。您在這裏:

List<decimal> matchingDoors db.tags 
    .Where(x => x.user_id == userId && (null == SystemId|| x.syid == SystemId)) 
    .GroupBy(x => x.door_id)   
    .Where(x => x.Any(y => tags.Contains(y))) //this is where magic 
    .Select(x => x.Key).ToList<decimal>(); 
+0

可愛。朋友,謝謝。 –

相關問題