我正在使用Dynamic Linq
withLinq to Entities
所以,我List<Person>
用这段代码测试了正常,一切正常:
List<Person> per = new List<Person>();
per.Add(new Person { IdNo = "1", LastName = "test", MiddleName = "go", FirstName = "let" });
per.Add(new Person { IdNo = "2", LastName = "hope", MiddleName = "is", FirstName = "way" });
per.Add(new Person { IdNo = "3", LastName = "must", MiddleName = "be", FirstName = "human" });
per.Add(new Person { IdNo = "4", LastName = "thing", MiddleName = "anywhere", FirstName = "can" });
per.Add(new Person { IdNo = "5", LastName = "bird", MiddleName = "fly", FirstName = "away" });
List<object> paramObjects = new List<object>();
List<string> fields = new List<string>();
fields.Add("IdNo == @0");
paramObjects.Add("1");
fields.Add("or (LastName + \", \" + MiddleName + \" \" + FirstName).Contains(@1)");
paramObjects.Add("m");
var where = string.Join(" ", fields.ToArray());
var toParam = paramObjects.ToArray();
var query = per.AsQueryable().Where(where, toParam).ToList();
当我Linq To Entities
接近时。
using(var con = new DbContext())
{
var query = con.Person.Where(where, toParam).ToList();
}
我收到了这个错误:
LINQ to Entities 无法识别方法 'System.String Concat(System.Object, System.Object)' 方法,并且此方法无法转换为存储表达式。
我的问题是:
在我使用Dynamic Linq的示例中,如何Concat
使用 base 字符串?任何人都可以帮助我吗?Linq To Entities