문제

I am having trouble with this error message as the line it errors on is not actually using Distinct() at all. I am wondering if it is something to do with the IEqualityComparer I've implemented?

It creates an unsupported exception in a view on this line, specifically on .Count():

tr style="display: @( Model.FeaturedOffers.Count() == 0 ? "" : "none" ) " id="none">

Here is the IEqualityComparer class:

public class RewardOfferEqualityComparer : IEqualityComparer<OfferOverviewViewModel>
{
    public bool Equals(OfferOverviewViewModel x, OfferOverviewViewModel y)
    {
        return Equals(x.OfferId, y.OfferId);
    }

    public int GetHashCode(OfferOverviewViewModel x)
    {
        return x.OfferId.GetHashCode();
    }
}
도움이 되었습니까?

해결책

Found that calling .ToList().Distinct() instead of .Distinct() solved the problem.

Found answer here

다른 팁

You might not be using Distinct(), but somehere in the chain of enumerables represented by Model.FeaturedOffers I'm guessing there's an IQueryable expression that's using a Distinct call that is not supported by the underlying provider - for example Linq to SQL or Entity Framework.

For example - if you are querying a Table in Entity Framework and passing your own comparer then that most certainly won't work - since there's no way for EF to re-implement the comparer in SQL or eSQL

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top