如何只使用一个类进行两次比较

本文关键字:比较 两次 一个 | 更新日期: 2023-09-27 17:59:05

我有一个model:

public class Parameter
{
    [Key]
    public int paramID { get; set; }
    [Display(Name = "No.")]
    public int paramNo { get; set; }
    [Required]
    [Display(Name = "Title")]
    public string parameter { get; set; }
    [Display(Name = "Meaning")]
    public string description { get; set; }
    [Display(Name = "Synonym")]
    public string synonym { get; set; }
    public int catID { get; set; }
    public virtual ICollection<CompareParameter> CompareParameters { get; set; }
}

我需要添加一个模型,将参数中的所有对象与参数中的每个其他对象进行比较。到目前为止,我有这个:

public class CompareParameter
{
    [Key]
    public int CompareID { get; set; }
    public int paramID1 { get; set; }
    public int paramID2 { get; set; }
    public virtual Parameter Parameters { get; set; }
    public virtual Parameter Parameters2 { get; set; }
}

其中paramID1从Parameter获取密钥,paramID2执行相同操作。只是它目前似乎不起作用。

有什么想法吗?

===更新问题===

以我给出的两个模型为例,我应该对CompareParameter做些什么来构建一个控制器和一个具有同一类的两个下拉列表的视图。这样做的目的是让我可以将它与另一个可能产生结果的类联系起来。

如何只使用一个类进行两次比较

您应该从Comparer派生Parameter类,并以这种方式实现比较。