我正在寻找一个简单的解决方案,用于在c#wpf中进行基于表单的搜索。
我的班级看起来像
public class Member
{
public int id { get; set; }
public string MNR { get; set; }
public int htblAnrede_id { get; set; }
public string Name { get; set; }
public string Vorname { get; set; }
public string Grad { get; set; }
public Nullable<System.DateTime> GebDat { get; set; }
public Nullable<System.DateTime> EinOed { get; set; }
public virtual htblAnrede htblAnrede { get; set; }
public virtual htblAusGrund htblAusGrund { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<tblBasisKennzeichen> tblBasisKennzeichen { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<tblBasisKontakte> tblBasisKontakte { get; set; }
}
它绑定到wpf用户控件。
在我的情况下,我打开一个表单,并在一些字段中写一些东西。之后,我将不得不从DataContext中检查每个属性,子对象的每个属性以及列表中每个对象的每个属性,以选择列表中的匹配项。
是否有解决方案或第三方工具,我可以使用它来简化,或者我必须自己检查一切?
为什么不在Member类中添加Equals方法,只需在需要的地方调用它:
public bool Equals(Member other)
{
if(other.id != this.id)
return false;
if(!other.htblAnrede.Equals(this.htblAnrede))
return false;
// fill in the other checks here
return true;
}
你必须对每个被比较的模型这样做,例如htblAnrede,tblBasisKennzeichen等