更新时间:2023-02-14 09:28:50
好的我弄明白了。我把它转换为AsEnumerable然后做了我的检查,然后把它转换回AsQueryable。
var entrys1 =来自in entrys.AsEnumerable()
select new
{
a.TemporaryPermitID,
a.TemporaryPermitNumber,
a.EventName,
a.FromDate,
a.ToDate,
a.Organization,
a.PermitDescription
};
entrys1 = entrys1.Where(a1 => a1.TemporaryPer mitNumber.ToString()。包含(pattern.TemporaryPermitNumber.ToString()));
entrys = entrys1.AsQueryable();
不确定它是否是***解决方案,但它有效且我很高兴结果
I have this query where I'm trying to see if their is part of the value
var entrys = from a in _Context.Permits
orderby a.Organization ascending
select new
{
a.PermitID,
a.PermitNumber
};
entrys = entrys.Where(a1 => a1.PermitNumber.Value.ToString().Contains(pattern.PermitNumber.ToString()));
Gives me error,
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
I've read other post that says:
hat error means LINQ to Entities doesn't
know how to generate SQL for that method call. You could materialize
the query first (call ToList(), ToArray(), First() or something else
that causes the query to be executed), so the data is in memory, and
then do the concatination afterward. or use AsEnumerable()
But i'm not quite sure how to do it with my query.
Thanks
OK I figured it out. I converted it to AsEnumerable then did my checking and then just converted it back AsQueryable.
var entrys1 = from a in entrys.AsEnumerable()
select new
{
a.TemporaryPermitID,
a.TemporaryPermitNumber,
a.EventName,
a.FromDate,
a.ToDate,
a.Organization,
a.PermitDescription
};
entrys1 = entrys1.Where(a1 => a1.TemporaryPermitNumber.ToString().Contains(pattern.TemporaryPermitNumber.ToString()));
entrys = entrys1.AsQueryable();
Not sure if its the best solution, but it works and im happy