C# 自定义对象列表 - 使用 SQL Like 语句查找对象
本文关键字:对象 Like 语句 SQL 查找 自定义 列表 使用 | 更新日期: 2023-09-27 18:35:08
>我曾经有一个数据表,我会使用以下方法查询:
rows = dtpc.Select("POSTCODE LIKE '" + postcodeID + "%'");
这将返回许多行,然后我可以从数据表中删除这些行。
现在我使用的是客户对象列表而不是数据表。
[Serializable]
public class CUSTOMEROBJECT
{
public string Rep_code { get; set; }
public string Int_rep_hou { get; set; }
public string Int_rep_key { get; set; }
public string Fullname { get; set; }
public string Custcode { get; set; }
public string Category { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string Postcode { get; set; }
public string Country { get; set; }
public string Telephone { get; set; }
public double Lat { get; set; }
public double Lng { get; set; }
public string County { get; set; }
}
如何使用类似于上面使用的 LIKE 语句的内容找到一系列客户对象?
您可以使用
LINQ
customerList.Where(c => c.Postcode.StartsWith(postcodeID.ToString()));