区分大小写
public class RowComparer : IEqualityComparer<pt_registration > { CaseInsensitiveComparer myComparer = new CaseInsensitiveComparer (); public bool Equals(pt_registration t1, pt_registration t2) { if (myComparer.Compare(t1.emailAddress, t2.emailAddress) == 0 && myComparer.Compare(t1.firstName, t2.firstName) == 0 && myComparer.Compare(t1.lastName, t2.lastName) == 0) { return true ; } else { return false ; } } public int GetHashCode(pt_registration t) { return t.ToString().ToLowerInvariant().GetHashCode(); } }
不区分大小写
public class RowComparer : IEqualityComparer<pt_registration > { public bool Equals(pt_registration t1, pt_registration t2) { return (t1.emailAddress == t2.emailAddress && t1.firstName == t2.firstName &&t1.lastName==t2.lastName); } public int GetHashCode(pt_registration t) { return t.ToString().GetHashCode(); } }
在下边使用哦
IEnumerable<pt_registration > distinctRows = (from n in db.pt_registrations where n.bankID == BankID && (n.businessName == mybusiness.formal_name || n.businessName == "ALL" ) && n.timeRegistered >= Convert .ToDateTime(startDate) && n.timeRegistered < Convert .ToDateTime(endDate) select n).ToList().Distinct(new RowComparer()); IList<pt_registration > myRegList = distinctRows.ToList(); GrVw_Registration.DataSource = myRegList; GrVw_Registration.DataBind();