我们有启用了CDC的DB。我们必须根据提供的日期找到数据。所以我们通过db函数实现了数据获取。
代码块如下:
private IQueryable<Letter> GetLetterQuery(DateTime? date = null)
{
IQueryable<Letter> dataSource = null;
dataSource = DBContextHelper.Context.fnGetLetters(date);
return dataSource;
}
public List<Letter> GetLetters(int attemptID, int cycle)
{
var dataSource = GetLetterQuery(DBContextHelper.CurrentDataVersion).Where(u => u.AttemptID == attemptID && u.Cycle == cycle).ToList();
populateLettersChildEntities(dataSource, DBContextHelper.CurrentDataVersion);
return dataSource;
}
private void populateLettersChildEntities(List<Letter> letters, DateTime? date = null)
{
letters.ForEach(u =>
{
u.Documents = DBContextHelper.Context.fnGetDocuments(date).Where(d => d.LetterID == u.ID).ToList();
u.LetterDoctors = DBContextHelper.Context.fnGetLetterDoctor(date).Where(d => d.LetterID == u.ID).ToList();
u.LetterFields = DBContextHelper.Context.fnGetLetterFields(date).Where(d => d.LetterID == u.ID).ToList();
u.LetterDoctors.ForEach(d =>
{
d.Doctor = DBContextHelper.Context.fnGetDoctors(date).FirstOrDefault(q => q.IDdoctor == d.DoctorID);
d.Letter = u;
});
});
}
我们必须填写相关字段。我们的问题是它肯定导致许多db调用。有没有办法减少通话? AFAIK我们无法使用包含此类数据库调用。