事先感谢聆听我的问题。
我有一个Linq到Sql级,在我使用“观点”的Grid岛上正在展示具体特性。
首先,我通过部分班子对我的班级施加影响:
public string Owner { get; private set; }
public Int32 Documents { get; private set; }
partial void OnLoaded()
{
Owner = "PersonCompanyRoleMedicalExam";
Documents = sfdb.StoredFiles.Count(s => s.Owner == this.Owner && s.OwnerId == this.Id);
}
Next ill paste my ViewModel used for the Grid:
public class MedicalExamViewModel
{
public Int32 Id { get; set; }
public Int32 PersonCompanyRoleId { get; set; }
public Int32? PeriodInDays { get; set; }
public DateTime? ExamCompleted { get; set; }
public bool? MedicallyFit { get; set; }
public Int32 Documents { get; set; }
}
之后,我用我的电网发出亚克斯呼吁的方法,将其填满:
[GridAction]
public ActionResult _MedicalExamGridAjaxBinding(Int32 Id)
{
PersonCompanyRole personCompanyRole = db.PersonCompanyRoles.Single(p => p.PersonId == Id);
var model = from o in db.PersonCompanyRoleMedicalExams
where o.PersonCompanyRoleId == personCompanyRole.Id
select new MedicalExamViewModel
{
Id = o.Id,
PersonCompanyRoleId = o.PersonCompanyRoleId,
PeriodInDays = o.PeriodInDays,
ExamCompleted = o.ExamCompleted,
MedicallyFit = o.MedicallyFit,
Documents = o.Documents
};
return View(new GridModel
{
Data = model
});
}
在我刚刚结束的“老模型”一栏“从 d到 d”一栏,看物体一打基础{System.SystemException} ={“Class members ComppanyRoleSHEAppointment.Documents is unmapped}
更深入地将物体分解为系统例外。 系统外观,在InnerException中,它指出:_COM PlusExceptionCode = -532462766。
不可否认的是,在我的项目中,我使用完全相同的技术,在没有任何问题的情况下,把其他物体/模型列入清单,但有一个不同之处,即两者之间有一个关联表。 与此类似:个人——和;个人CompanyRole > 个人CompanyRoleM Exam. Person to PersonCompanyRole is a one-toone relationship and PersonCompanyRole to PersonCompanyRoleMedical Exam是一对一。 完全性在我的麻省方法中不见过去,因为当时我会有任何例外。
[GridAction]
public ActionResult _IncidentsGridAjaxBinding(Int32 Id)
{
var structures = db.sp_GetCompanyStructureDecendants(Id);
Collection<CompanyStructureIncident> companyStructureIncidents = new Collection<CompanyStructureIncident>();
foreach (sp_GetCompanyStructureDecendantsResult decendant in structures)
{
IEnumerable<CompanyStructureIncident> equipment = db.CompanyStructureIncidents.Where(r => r.CompanyStructureId == decendant.Id);
foreach (CompanyStructureIncident companyStructureIncident in equipment)
{
companyStructureIncidents.Add(db.CompanyStructureIncidents.Single(p => p.Id == companyStructureIncident.Id));
}
}
var model = from o in companyStructureIncidents
//where o.CompanyStructureId == Id
select new IncidentViewModel
{
Id = o.Id,
CompanyStructureId = o.CompanyStructureId,
DateOfOccurence = o.DateOfOccurence,
DateReported = o.DateReported,
Documents = o.Documents
};
return View(new GridModel
{
Data = model
});
}
希望能帮助。