Page というオブジェクトと、AssociatedAttributes というカスタム プロパティを持つ p というインスタンスがあります。私が次のことをした場合:
int numMatchingAttributes = p.AssociatedAttributes.Intersect( p.AssociatedAttributes ).Distinct( ).Count( ); 
p には 6 つの AssociatedAttributes がありますが、numMatchingAttributes は最終的に 0 になります。なぜ6に等しくないのですか?
AssociatedAttributesは Type List<Attribute>( Attributeis my own class, not System.Attribute) and AttributeimplementsIComparable<Attribute>です。implement を持っていませんでしたIEquatableか?
これはCompareToin Attribute の実装です:
public int CompareTo(Attribute other)
{
    return Id.CompareTo(other.Id);
}
IdタイプGuidです。
これは Page の AssociatedAttributes プロパティです。
public List<Attribute> AssociatedAttributes
        {
        get
            {
            List<Attribute> list = new List<Attribute>( );
            using (
                PredictiveRecommendor dbContext =
                    new PredictiveRecommendor()){
                if ( dbContext != null )
                    { 
                    IQueryable<Attribute> query = from a in dbContext.PageAttributes
                                                  where a.Page.Id.Equals(this.Id)
                                                  select a.Attribute;
                    list = query.ToList(); 
                    }
                }
            return list;
            }
        }
(dbContext は Telerik OpenAccess コンテキストです)
更新: これが最終的に機能したものです: In Page は次の方法です:
public int numberOfIntersectedAssociatedAttributes ( Page other )
        {
        using ( PredictiveRecommendor dbContext = new PredictiveRecommendor( ) )
            {
            IQueryable<Attribute> thisAssocAttributes = from a in dbContext.PageAttributes
                                                        where a.Page.Id.Equals( this.Id )
                                                        select a.Attribute;
            IQueryable<Attribute> otherAssocAttributes = from a in dbContext.PageAttributes
                                                         where a.Page.Id.Equals( other.Id )
                                                         select a.Attribute;
            IQueryable<Attribute> interSection = thisAssocAttributes.Intersect( otherAssocAttributes );
            return interSection.ToList( ).Count;
            }
        }
それは醜いですが、うまくいきます。