通过电子邮件地址过滤数据集,LINQ查询不工作
本文关键字:LINQ 查询 工作 数据集 电子邮件地址 过滤 | 更新日期: 2023-09-27 18:17:09
我有这个SQL查询过滤数据集的结果通过电子邮件地址:
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.
你能指出我哪里出错了吗?
问题可能出在字符大小写上。
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));