{"LINQ to Entities does not recognize the method 'Boolean IsLetter(Char)' method, and this method cannot be translated into a store expression."}

{"LINQ to Entities does not recognize the method 'Boolean IsLetter(Char)' method, and this method cannot be translated into a store expression."}

我想使用 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();

那是因为 char.IsLetter 不是 dbFunction

转换结果后即可申请whereToList()

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: 尝试为数据库查询确定一些其他 where 子句以限制结果。

我想试试 System.Data.Linq.SqlClient 命名空间中的 SqlMethods class。

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();