オブジェクトへのlinqを使用したクエリは、非常に読みやすく、素晴らしいものになると思います。例えば:
from person in db.Persons.ToList()
where person.MessageableBy(currentUser) ...
MessageableBy は、ストア式 (SQL) に変換できないメソッドです。
public bool MessageableBy(Person sender)
{
// Sender is system admin
if (sender.IsSystemAdmin())
return true;
// Sender is domain admin of this person's domain
if (sender.Domain.DomainId == this.Domain.DomainId && this.Domain.HasAdmin(sender))
return true;
foreach (Group group in this.Groups)
{
if (group.MessageableBy(sender))
return true;
}
// The person is attorney of someone messageable
if (this.IsAttorney)
{
foreach (Person pupil in this.Pupils)
if (pupil.MessageableBy(sender))
return true;
}
return false;
}
問題は、これはスケールしないと思うことです。データベースにいくつかのエントリがあることにすでに気付いているので、大規模なデータベースでは想像できません。
したがって、問題は次のとおりです。 エンティティへの linq とオブジェクトへの linq を混在させる必要があります (つまり、「where」の一部を ICollection に適用し、「where」の一部を .ToList() の結果に適用しますか? linq のみを使用する必要があります。エンティティに、非常に長い文で終わる?