我有一個數據庫表列,其中包含逗號分隔的字符串列表。我需要在這個表格中查詢逗號分隔列中的字符串。使用String.Split()。在CSV列上使用Linq/Lambda包含()
表:
public class MyObject
{
public string sIds { get; set; }
...
}
如果在我的表中的SID列包含:
sIds = "DG,VO,XX,AB"
和我執行下面的代碼:
string _sId = "AB";
List<MyObject> designParams = _context.DesignParams
.AsNoTracking()
.Where(c => c.sIds.Split(',').Contains(_sId))
.Select(c => c)
.ToList();
我得到NotSupportedException異常:LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method, and this method cannot be translated into a store expression.
。
有很多類似於我的問題的文章,但我一直未能找到確切的解決方案。我的代碼有什麼問題嗎?或者有什麼不同的方法呢?
顯示的'MyObject'請 – nozzleman 2014-12-05 06:39:49
類定義爲什麼你甚至需要分割字符串?爲什麼不在Ids列上做一個String.Contains? – CSharpie 2014-12-05 07:27:07
您是否嘗試過不使用'.AsNoTracking()'?對我來說,其餘的代碼應該沒問題。 – Kutyel 2014-12-05 07:28:22