次の式を使用して、ドロップダウン リストの LINQ を選択しようとしています。
protected void PopulateInstitutionsDropDownList(Team currentTeam)
{
var institutions = from d in db.Institutions
where !(currentTeam.Institutions.Select(x => x.ID).Contains(d.ID))
orderby d.InstitutionName
select d;
List<Institution> i = institutions.ToList();
ViewBag.Institutions = new SelectList(i, "ID", "InstitutionName");
}
ただし、これにより、例外が発生します: タイプ 'Refusion.Models.Institution' の定数値を作成できません。この型では、プリミティブ型または列挙型のみがサポートされています。
これが、Compare オブジェクトなしでは 2 つのオブジェクトを直接比較できないことを知っているため、新しいコレクションの ID だけを選択しようとする理由です。
なぜこれが機能しないのですか?