如何解决除C#中的问题以外的实体?

时间:2018-11-14 09:23:15

标签: c# entity-framework

我想从其他数据库中的值中找到常见的值。并在包含不同数据库值的情况下插入其他数据库。

<script type="application/ld+json">+schema app
{ 
  "@context": "http://schema.org/",
  "@type": "web master",
  "name": "schema.org/person",
  "Struturedata": 
    { 
       "@type": "Person",
       "name": "chema mpnrroy josepinedamonroy",
       "birthDate": "10/19/1982"
    },
  "geng": "male",
  "Mecanismo":microdata. ".estructuredate./" validador
}
</script>

但不常见。如何解决常见价值问题。

1 个答案:

答案 0 :(得分:1)

要从set operation选择,

Except

产生两个序列的集合差异,一个序列的元素未出现在第二个序列中。

a.Except(b); // a U b 

enter image description here

要比较某些自定义字段的对象集,必须实现IEqualityComparer<T>

public class Student                  
{ 
    public string Name { get; set; }
    public int CountryCode { get; set; }
    public int BranchCode  { get; set; }
    public int Code { get; set; }
}

public class StudentComparer : IEqualityComparer<Student>
{
    public bool Equals(Student x, Student y)
    { 
        if (Object.ReferenceEquals(x, y)) return true;

        return x != null 
                && y != null 
                && x.CountryCode.Equals(y.CountryCode) 
                && x.BranchCode.Equals(y.BranchCode);
    }

    public int GetHashCode(Student obj)
    {
        int hashCountryCode = obj.CountryCode.GetHashCode();
        int hashBranchCode  = obj.BranchCode.GetHashCode();

        return hashCountryCode ^ hashBranchCode;
    }
}

var toInstertInB = a.Except(b, new StudentComparer());