2011-08-05 13 views
0

私はEntity Frameworkのモデルで働いていますし、私はこのような表現を書いています:私はDistinct機能で書くべきことEntity Frameworkのモデル個別機能

medication = objectContext.vClientMedication.Distinct().ToList(); は、ユニークなBrandNameを取得します。 BrandNameはvClientMedicationの属性です。

ありがとうございます。

enter image description here

+0

に[特定の財産上の個別のLINQ](HTTPの可能重複クエリを記述した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; }} 

を使用することができます:// stackoverflowのを.COM /質問/ 489258/LINQ-異なるオン特に-性) –

答えて

2
medication = objectContext.vClientMedication.Select(o => o.BrandName).Distinct().ToList(); 
+0

こののみreturブランド自体の名前ではありません。 – maniacneron

+0

maniacneronが正しいです。 urメソッドを使用して文字列が返されています。 – asma

1

あなたはその後、

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

更新質問を参照してください。私は、urコードを使用した後にエラーの画像を追加しました。私のミス – asma

+0

申し訳ありません私はそれを編集しています。 – maniacneron

+0

次のエラーがあります。 '' Pc.PrecisionCare2.DAL.Consumer.Medication.ConsumerMedicationDAO.CustomEqualityComparer 'は、インターフェイスメンバー' System.Collections.Generic.IEqualityComparer .GetHashCode(Pc.PrecisionCare2)を実装していません。 ModelTypes.vClientMedication) ' – asma

関連する問題