【发布时间】:2023-03-13 17:54:01
【问题描述】:
我正在尝试使用动态 linq 从使用 Entity 的数据库中获取人的子集 框架 (EF)。使用 contains 操作时遇到问题。这是实体 对于 People 表:
public class Person
{
public string Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
}
这是一个成功的查询。
var people = personContext
.People
.OrderBy("id asc")
.Skip(0)
.Take(5)
.ToList();
请注意,我在 OrderBy 方法中使用了动态 linq。但是,当我尝试申请时 过滤,我得到一个异常。
var people = personContext
.People
.Where("id.Contains(15)")
.OrderBy("id asc")
.Skip(0)
.Take(5)
.ToList();
我想要返回的是 id 包含子字符串“15”的人的子集,例如:
"015", "115", "151", "152", etc.
当我执行代码时,出现以下错误。
System.Linq.Dynamic.ParseException was unhandled by user code
Message=No applicable method 'Contains' exists in type 'String'
判断Id字段是否包含字符串“15”的语法是什么?
【问题讨论】:
标签: c# sql entity-framework linq dynamic-linq