我不能得到QueryObjectGraph添加INCLUDE子表,如果我的生命依賴於它...我錯過了什麼?卡住第三天的東西,應該是簡單的: -/EF多對多dbset.In包括DAL GenericRepository
DAL:
public abstract class RepositoryBase<T> where T : class
{
private MyLPL2Context dataContext;
private readonly IDbSet<T> dbset;
protected RepositoryBase(IDatabaseFactory databaseFactory)
{
DatabaseFactory = databaseFactory;
dbset = DataContext.Set<T>();
DataContext.Configuration.LazyLoadingEnabled = true;
}
protected IDatabaseFactory DatabaseFactory
{
get;
private set;
}
protected MyLPL2Context DataContext
{
get { return dataContext ?? (dataContext = DatabaseFactory.Get()); }
}
public IQueryable<T> QueryObjectGraph(Expression<Func<T, bool>> filter,
params string[] children)
{
foreach (var child in children)
{
dbset.Include(child);
}
return dbset.Where(filter);
}
... DAL庫
public interface IBreed_TranslatedSqlRepository : ISqlRepository<Breed_Translated>
{
}
public class Breed_TranslatedSqlRepository : RepositoryBase<Breed_Translated>,
IBreed_TranslatedSqlRepository
{
public Breed_TranslatedSqlRepository(IDatabaseFactory databaseFactory)
: base(databaseFactory)
{}
}
BLL回購:
public IQueryable<Breed_Translated>
QueryObjectGraph(Expression<Func<Breed_Translated, bool>> filter,
params string[] children)
{
return _r.QueryObjectGraph(filter, children);
}
控制器:
var breeds1 = _breedTranslatedRepository
.QueryObjectGraph(b => b.Culture == culture, new string[] { "AnimalType_Breed" })
.ToList();
我不能達到Breed.AnimalType_Breed.AnimalTypeId
..我可以鑽到Breed.AnimalType_Breed那麼intelisense期望一個表達式?
線索如有DB表:大膽是許多一對多 品種,Breed_Translated,AnimalType_Breed,AnimalType,...
謝謝拉迪斯拉夫,我能夠在一小時內再次開始編碼,所以我會更多地摔跤。再次感謝你提供的建議。 – Bryant
我知道它使用First()!!!!!!!!!! :-)我現在必須清理它[我會嘗試反正..mine是如此醜陋的大聲笑],但感謝幫助x 1000不再被卡住是一種偉大的感覺!無論如何這裏是什麼工作: – Bryant
var breeds1 = _breedTranslatedRepository.QueryObjectGraph(b => b.Culture ==文化,「品種」,「Breed.AnimalType_Breed」)。 VAR breeds2 = breeds1.Where(A => a.Breed.AnimalType_Breed.First()。AnimalTypeId == animalTypeId).ToList() 。選擇(A =>新SelectListItem() { 文本= a.BreedNameTranslated , Value = a.BreedId。ToString(), }); return Json(breeds2); – Bryant