Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all:

I met a question that lets me to be disturbed today, although it can not produce by changing code line position, i want to know why it happens.


Steps:
1. I used Linq to get data from database, example code:

Quote:
var ret = (from c in getComment
join cr in context.GetTable<commentreply>() on c.ID equals cr.CommentID into crs
join oc in context.GetTable<ownercomment>() on c.ID equals oc.CommentID into ocs
from cr1 in crs.DefaultIfEmpty()
where c.EnumDataEntityStatus == EnumDataEntityStatus.Normal || IsForUserInfoSearch
from oc1 in ocs.DefaultIfEmpty()
where c.EnumDataEntityStatus == EnumDataEntityStatus.Normal || IsForUserInfoSearch
select new CommentSearchModel { comment = c, reply = cr1, ownerComment = oc1 });


2. there are two lines code, A and B, and , there are many "Linq where Sentence " lines code in front of A and B.

A is
ret = ret.Where(P => P.comment.OrderNumber.Contains(req.OrderNumber.Trim()));


B is
var excludeIDList = ret.Where(q => ((now - q.comment.CheckOutDate.Date).TotalDays > 30 && q.comment.EnumCommentStatus == 0 && q.comment.EnumOwnerCommentedStatus == 0) || q.comment.EnumCommentStatus == EnumCommentStatus.Expired).Select(x => x.comment.ID);

if (req.SpecificCondition == EnumSpecificQueryCondition.AllForMerchant)
    ret = ret.Where(q => !excludeIDList .Contains(q.comment.ID));


B is executed,then will product a new object "
{System.Data.Linq.DataQuery<TuJia.Business.Customer.Contract.CommentSearchModel>}
" .

3. question:

If A is in the front B, as execute ret.toList(), exception will be produced.
If B is in the front A, as execute ret.toList(), exception will be produced.
4. Exception:
because, i use Chinese Operation System, my exceptions are Chinese, i will translate them into English, but perhaps be incorrect.

Exception:
Quote:
For method String.Contains, only parameters that can be evaluated on the client are supported


Chinese:
内容:对于方法 String.Contains,只支持可在客户端上求值的参数


5. At last, i hope that everybody can provide me with any information about it, i want to know the reason that produce exception.

Quote:
Thanks in advance!


What I have tried:

<pre lang="c#">
Posted
Updated 11-Jul-17 3:39am
v6

1 solution

Try using SqlMethods.Like instead of contains.

Like this...

where SqlMethods.Like(columnName,"%"+keyword+"%")
 
Share this answer
 
Comments
Aaron Bo 11-Jul-17 22:33pm    
thanks! but, i want to know reason why they are different.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900