我想使用LINQ获取数据库中的所有项目,其中标题以特殊字符或数字开头,我已经尝试了下面的代码,但它不起作用。
由于
result = (from asset in _db.Query<Asset>()
where !char.IsLetter(asset.Title[0])
select new AssociatedItem { Id = asset.AssetId, Title = asset.Title, Type = Constants.FeedbackTypes.ASSET }).ToList();
答案 0 :(得分:1)
那是因为char.IsLetter不是dbFunction。
转换结果where
ToList()
result = (from asset in _db.Query<Asset>()
select new AssociatedItem { Id = asset.AssetId, Title = asset.Title, Type = Constants.FeedbackTypes.ASSET }).ToList()
.Where(a => !char.IsLetter(a.Title[0])).ToList();
PS:尝试识别db查询的其他where子句以限制结果。
答案 1 :(得分:1)
我会从SqlMethods
命名空间中给出System.Data.Linq.SqlClient
类。
result = (from asset in _db.Query<Asset>()
where !SqlMethods.Like(asset.Title, "[a-Z]%")
select
new AssociatedItem
{
Id = asset.AssetId,
Title = asset.Title,
Type = Constants.FeedbackTypes.ASSET
}).ToList();