目前我有一个错误,阻止我从数据库中返回任何数据。我通过了 LINQ 联接,然后当我将鼠标悬停在保存我的数据的模型上时,它会指出错误消息。我确实注释掉了 Join 中的几行,它有效,所以我已经确定了错误的位置。我只需要一些帮助来理解错误及其发生的原因。
SQL 存储库:
public IQueryable<ClaimNumberReport> GetClaimsByClaimNumber(int ClientID, int ClaimID) {
return (from d in camOnlineDb.Details
join a in camOnlineDb.Areas
on new { a = d.ClientID, b = d.AreaID ?? 0 }
equals new { a = a.ClientID, b = a.AreaID }
where d.ClientID == ClientID
join r in camOnlineDb.Reasons
on new { a = d.ClientID, b = d.ReasonID ?? 0 }
equals new { a = r.ClientID, b = r.ReasonID }
join sd in camOnlineDb.SuppDepts
on new { a = d.ClientID, b = d.CategoryID ?? 0 }
equals new { a = sd.ClientID, b = sd.CategoryID }
join h in camOnlineDb.Headers
on new { d.ClientID, d.ClaimID }
equals new { h.ClientID, h.ClaimID }
where d.ClaimID == ClaimID
join su in camOnlineDb.Suppliers
on new { h.ClientID, h.SupplierID }
equals new { su.ClientID, su.SupplierID }
join cp in camOnlineDb.ClaimPacks
on new { h.ClientID, h.ClaimID }
equals new { cp.ClientID, cp.ClaimID }
join rev in camOnlineDb.Reviews
on new { h.ClientID, h.ReviewID }
equals new { rev.ClientID, rev.ReviewID }
join revp in camOnlineDb.ReviewPeriods
on new { a = rev.ClientID, b = rev.ReviewPeriodID ?? 0 }
equals new { a = revp.ClientID, b = revp.ReviewPeriodID }
join st in camOnlineDb.Statuses
on new { a = d.ClientID, b = d.StatusID ?? 0 }
equals new { a = st.ClientID, b = st.StatusID }
join stcm in camOnlineDb.StatusCategoryMappings
on new { st.ClientID, st.StatusID }
equals new { stcm.ClientID, stcm.StatusID }
join stc in camOnlineDb.StatusCategories
on new { stcm.StatusCategoryID }
equals new { stc.StatusCategoryID }
select new ClaimNumberReport {
// Changed type to sub type and dropped type
TypeID = d.ClaimTypeID,
// Needs changed to PDF file address
CPAttached = cp.Comment,
ReviewName = revp.ReviewPeriodName,
ClaimID = d.ClaimID,
Line = d.ClaimLine,
AccountNo = su.AccountNo,
SupplierName = su.SupplierName,
Amount = d.Amount,
Status = st.StatusDesc,
DateSent = d.DateSent,
DayOS = d.DaysOS,
NominalPeriod = d.NominalPeriod,
SLInvoiceNo = d.SLInvoiceNo,
Area = a.AreaDesc,
DebitRef = d.DebitFile,
DebitDate = d.JournalDate,
DeductDate = d.DeductDate,
StatusCategoryDesc = stc.StatusCategoryDesc,
APLReason = r.ReasonDesc,
DeptNo = sd.DepartmentID,
DeptName = sd.DepartmentName,
// The below 4 need to change, I believe that this may be done on the view or controller.
//Settled = d.Amount,
//Cancelled = d.Amount,
//Conversation = d.Amount,
//WIP = d.Amount
});
}
控制器:
public ActionResult ClaimNumberReportSelection(int ClientID, int ClaimNo) {
int ClaimID = Convert.ToInt32(ClaimNo);
ClaimNumberViewModel ClaimNumberModel = new ClaimNumberViewModel {
ReportData = reportRepo.GetClaimsByClaimNumber(ClientID, ClaimID),
ReportTitle = "Claim Number Report",
ReportDescription = "Report for " //+ reportRepo.GetClaimsByClaimNumber(ClientID, ClaimID).Where(r => r.ClaimID == ClaimID).Select(r => r.ClaimID).FirstOrDefault()
};
return View("ClaimNumberReport", ClaimNumberModel);
}
索赔编号报告类:
public class ClaimNumberReport {
public int ClaimID { get; set; }
public string ReviewName { get; set; }
public char? TypeID { get; set; }
public char OldTypeID { get; set; }
public string CPAttached { get; set; }
public int? Line { get; set; }
public string AccountNo { get; set; }
public string SupplierName { get; set; }
[DataType(DataType.Currency)]
public decimal? Amount { get; set; }
public string Status { get; set; }
public DateTime? DateSent { get; set; }
public int? DayOS { get; set; }
public int? NominalPeriod { get; set; }
public string SLInvoiceNo { get; set; }
public string Area { get; set; }
public string DebitRef { get; set; }
public DateTime? DebitDate { get; set; }
public DateTime? DeductDate { get; set; }
public string StatusCategoryDesc { get; set; }
public string APLReason { get; set; }
public int ClientID { get; set; }
public int DeptNo { get; set; }
public string DeptName { get; set; }
[DataType(DataType.Currency)]
public decimal Settled { get; set; }
[DataType(DataType.Currency)]
public decimal Cancelled { get; set; }
public decimal Conversation { get; set; }
[DataType(DataType.Currency)]
public decimal WIP { get; set; }
}
它指出了我进入视图并尝试显示数据的错误消息,但是当我将鼠标悬停在模型上的返回视图行上时,它会显示错误消息。
这与数据类型 char 有关。在我的数据库中,ClaimTypeID是一个字符。但是,在Visual Studio中,char与SQL char不同,因为它只允许一个字符。所以我不得不把它改成一个字符串。