问题描述:

Building a list from model in C# using Entity Framework. I am using LINQ to try to match up the first 6 or 7 characters in a field. In a language other than C# I would use a regex expression.. or in SQL a "Like" with wildcard symbols. Below is the code I'm using, and I am getting an Argument exception.

List<InvoiceHeader> tempData = db.InvoiceHeader

.Where(f => f.ivh_invoicenumber.Any(t => f.ivh_invoicenumber.StartsWith(temp))).ToList();

网友答案:

If ivh_invoicenumber and temp are of type string

var tempData = db.InvoiceHeader.Where(f => f.ivh_invoicenumber.StartsWith(temp)).ToList();

If temp is array of strings:

var tempData = db.InvoiceHeader
                 .Where(f => temp.Any(t => f.ivh_invoicenumber.StartsWith(t))).ToList();
相关阅读:
Top