我有这个SQL查询用于通过电子邮件地址过滤DataSet结果:
SELECT t.[ID]
,s.[Email]
,[StockSymbol]
,[StockID]
,[SubscriberID]
,[IP]
,[App]
,[CachedID]
FROM [NoRiba].[dbo].[Transaction] t
JOIN Subscriber s ON t.SubscriberID = s.ID
WHERE s.[Email] LIKE '%SerachString%'
问题是:我想对LINQ查询执行相同的操作,但是下面的WHERE子句不起作用:
var transactions = (
from t in db.Transactions
join s in db.Subscribers on t.SubscriberID equals s.ID
orderby t.TimeStamp descending
select new { t.TimeStamp, t.StockSymbol, t.StockID, t.SubscriberID, t.IP, t.App, t.CachedID, s.Email })
.Skip(param.iDisplayStart).Take(param.iDisplayLength);
if (!String.IsNullOrEmpty(param.sSearch))
{
transactions = transactions.
Where(s => s.Email.Contains(param.sSearch));
} // This code returns zero rows after executing and searching with any string.
你能指出我在哪里弄错了吗?
答案 0 :(得分:2)
问题可能在于字符大小。
string search = param.sSearch.ToLower();
transactions = transactions.Where(s => s.Email.ToLower().Contains(search) ||
s.Email.ToLower().Contains(search.Replace(" ", String.Empty)));
或者
string search = param.sSearch.ToLower().Replace(" ", String.Empty);
transactions = transactions.Where(s => s.Email.ToLower().Contains(search));