現在、完全な汎用リポジトリがありますが、1つの機能がありません。それは、
Include()をFind()
一緒に使用することです。
だから今私は持っています:
public E FindById<E>(int id) where E : class
{
return DataContext.Set<E>().Find(id);
}
を使用して呼び出されます
var person = PersonRepo.FindById<Person>(personId);
私は次のようなものが欲しいです:
var person = PersonRepo.FindByIdWithIncludes<Person>(personId,new[]{"State.Address"});
したがって、この線に沿った何か(これは単なるテストです):
public E FindByIdWithIncludes<E>(int id, string[] includes) where E : class
{
var entitySet = DataContext.Set<E>();
DbQuery<E> entityQuery;
foreach (var include in includes)
{
entityQuery = entitySet.Include(include);
}
return entityQuery.Find(id); //this is were it breaks
}
出来ますか?