Отличительная функция модели Entity Framework - PullRequest
0 голосов
/ 05 августа 2011

Я работаю в Entity Framework Model и пишу такое выражение:

medication = objectContext.vClientMedication.Distinct().ToList(); Что я должен написать в Distinct функции, чтобы получить уникальный BrandName. BrandName является атрибутом vClientMedication.

Спасибо.

enter image description here

Ответы [ 2 ]

2 голосов
/ 05 августа 2011
medication = objectContext.vClientMedication.Select(o => o.BrandName).Distinct().ToList();
1 голос
/ 05 августа 2011

вы можете использовать IComparer

 public class CustomEqualityComparer : IEqualityComparer<vClientMedication>
{
    #region IEqualityComparer Members

    public bool Equals(vClientMedication x, vClientMedication y)
    {
        if ((x.BrandName == y.BrandName))
            return true;
        else
            return false;
    }}

, а затем написать свой запрос

medication = objectContext.vClientMedication.Distinct(new
CustomEqualityComparer()).ToList();
...