2012-01-17 66 views
0

Linq我有下面的注意完整,但你有想法: 我需要檢查TruckNbr不以「100」或「1000」結束。 如何做到這一點在下面的查詢LINQ不會以某些字符結尾

var truck = (from tr in DataContext.Trucks 
       where tr.TruckNbr != ... 
       select tr).ToList() 
+5

是'TruckNbr'真的數還是一個'String'? – Yuck 2012-01-17 20:06:29

回答

4

假設TruckNbr是一個字符串。

var truck = (from tr in DataContext.Trucks 
      where !(tr.TruckNbr.EndsWith("100") || tr.TruckNbr.EndsWith("1000")) 
      select tr).ToList() 
2

如果TruckNbr是可以做到這一點的數據庫varchar

var truck = (from tr in DataContext.Trucks 
      where tr.TruckNbr.EndsWith("100") == false 
       && tr.TruckNbr.EndsWith("1000") == false 
      select tr).ToList(); 
1

其他的答案承擔TruckNbr是一個字符串;這裏是你會怎麼做假設TruckNbr是一個數字:

var truck = (from tr in DataContext.Trucks 
      where tr.TruckNbr%1000 != 100 && tr.TruckNbr%10000 != 1000 
      select tr).ToList()