0

At the moment I have an error which prevents me from returning any data from my database. I get past my LINQ join and then when I hover over the model which holds my data, it states the error message. I did comment out few lines in the Join and it worked so I have identified where the errors at. I just need some help understanding the error and why it occurs.

SQL Repository:

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
                    });
        }

Controller:

 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);

        }

ClaimNumberReportClass:

  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; }
    }

It states the error message one I get to the view and try to display data but it shows the error message when I hover over the return view line on the model.

Andrew Kilburn
  • 2,251
  • 6
  • 33
  • 65

1 Answers1

0

It was to do with the datatype char. In my database ClaimTypeID is a char. However in Visual Studio a char is different to an SQL char as it only is allowed one character. So I had to change it to a string instead.

Andrew Kilburn
  • 2,251
  • 6
  • 33
  • 65
  • Sort of. `char`is not a [valid primitive type](https://msdn.microsoft.com/en-us/library/vstudio/ee382832(v=vs.110).aspx) in Entity Framework. It's perfectly valid in C# and .NET, but EF maps any character type (even `char(1)`) to string. – D Stanley Jun 15 '15 at 14:15