Hi any one please let me know why i am getting below error.
An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: Unable to create a constant value of type 'Infragistics_Example.clsCompanyByPeriod+PivotedClass'. Only primitive types or enumeration types are supported in this context. below code i am using
List<Invoice> InvoiceDtls;
List<InvoiceDetailsByRows> InvoiceDetailsByRows;
InvoiceDetailsByRows = (from P2 in M4.tbl_Invoice
join PD in M4.tbl_InvoiceDetails on P2.Invoice_Id equals PD.Invoice_Id
// where PD.TAG_ID == TagId
select new InvoiceDetailsByRows
{
InvoiceId = PD.Invoice_Id.Value,
InvoiceDetailsNo = PD.InvoiceDetailsNo,
Amount = PD.Amount.Value,
InvoiceDetailId = PD.InvoiceDetails_Id,
InvoiceDate = PD.InvoiceDate.Value,
}).ToList();
List<PivotedClass> AfterPIVOT;
AfterPIVOT = InvoiceDetailsByRows
.GroupBy(c => c.InvoiceId)
.Select(g => new PivotedClass
{
InvoiceId = g.Key,
JanY1 = g.Where(c => c.InvoiceDate.Month == 1).Sum(c => c.Amount),
FebY1 = g.Where(c => c.InvoiceDate.Month == 2).Sum(c => c.Amount),
MarY1 = g.Where(c => c.InvoiceDate.Month == 3 ).Sum(c => c.Amount),
AprY1 = g.Where(c => c.InvoiceDate.Month == 4 ).Sum(c => c.Amount),
MayY1 = g.Where(c => c.InvoiceDate.Month == 5).Sum(c => c.Amount),
Summary = g.Sum(c => c.Amount),
}).ToList();
InvoiceDtls = (from P2 in M4.tbl_Invoice // if storing this tbl_Invoice data into a variable then using this variable here it's working but while using enity(tbl_Invoice) is throwing error
select new Invoice
{
InvoiceNo = P2.InvoiceNo,
InvoiceDetailsListRows = (from PD in AfterPIVOT
where PD.InvoiceId == P2.Invoice_Id
select new PivotedClass
{
InvoiceId = PD.InvoiceId,
JanY1 = PD.JanY1,
FebY1 = PD.FebY1,
MarY1 = PD.MarY1,
AprY1 = PD.AprY1,
MayY1 = PD.MayY1,
}).ToList()
}).ToList();
return InvoiceDtls;