这很模糊。所以任何帮助将不胜感激。但为什么我的'workPhase'变量不会被设置为对象的实例?我想不明白。这是我的代码:
public WorkPhaseMultiCodingManageEdit.Command Handle(Query query)
{
var workPhase = _db.WorkPhases.FirstOrDefault(x => x.Id == query.WorkPhaseIds.FirstOrDefault());
var result = new WorkPhaseMultiCodingManageEdit.Command();
result.WorkPhaseIds = query.WorkPhaseIds;
result.Job = workPhase.Job;
result.JobId = workPhase.JobId;
result.Disabled = !_authService.DoesUserHaveAccess(Feature.WBSConfigurationCodingSection);
var codingFields = _codingFieldService.GetCodingFields(workPhase);
foreach (var codingFieldItem in codingFields)
{
var codingValuesForThisCodingField = _db.WorkPhases
.SelectMany(x => x.CodingFields)
.Where(x => query.WorkPhaseIds.Contains(x.WorkPhaseId))
.Where(x => x.CodingFieldValue.CodingFieldId == codingFieldItem.CodingFieldId)
.Select(x => x.CodingFieldValueId)
.ToList();
if (codingValuesForThisCodingField.Distinct().Count() > 1 ||
(codingValuesForThisCodingField.Count > 0 && codingValuesForThisCodingField.Count != query.WorkPhaseIds.Count))
{
var options = new List<DropDownItem>() { new DropDownItem() { Id = -1, Name = "Various" } };
options.AddRange(codingFieldItem.Options);
codingFieldItem.Options = options;
codingFieldItem.CodingFieldValueId = -1;
}
else if (codingValuesForThisCodingField.Count() == query.WorkPhaseIds.Count)
{
codingFieldItem.CodingFieldValueId = codingValuesForThisCodingField.First();
}
else
{
codingFieldItem.CodingFieldValueId = 0;
}
result.CodingFields.Add(codingFieldItem);
}
return result;
}
}