我正在使用.NET framework 4.5.1
Linq to sql.
public class Part { public int PartID { get; set; } [required(ErrorMessage = "xxx")] public string Title { get; set; } [MaxLength(50)] [Index(IsClustered = false,IsUnique = false,Order =1)] public string Part_Number { get; set; } [MaxLength(50)] [Index(IsClustered = false,Order = 2)] public string Manufacturer_Number { get; set; } }
我在数据库中有大约250万个这样的实体.
第一种方法
var query = db.Parts.Where(s => s.Manufacturer_Number == sstring).ToList(); query.AddRange(db.Parts.Where(s => s.Part_Number == sstring).ToList()); query.AddRange(db.Parts.Where(s => s.Title == sstring).ToList());
第二种方法
var query = db.Parts.Where(s => s.Manufacturer_Number == sstring || s.Part_Number == sstring || s.Title == sstring).ToList();