EF 4.0 で作成されたモデルがあるとします。
ユーザー
役割
- 権限
各エンティティには、DeleteDate プロパティがあります。
特定のユーザー (Name =...) を取得し、ツリーに DeletedDate == null のアイテムを入れたい..
これは結果として匿名型射影で行う必要がありますが、2 より深い階層でこれを達成する方法がわかりません。
これは私がすでに持っているものです:
public MyProjection MyCall(string givenName)
{
var result = from s in context.Users
where (s.Name == givenName &&
s.DeletedDate == null)
select new
{
s,
roles = from r in s.Roles
where r.DeletedDate == null
select r
};
var outcome = result.FirstOrDefault();
if (outcome != null)
{
var myProjection = new MyProjection()
{
User = outcome.s,
Roles = outcome.roles
};
return myProjection;
}
return null;
}