ASP.Net Entity Framework Error: A member of the type, does not have a corresponding column in the data reader with the same name

Rockstar8
 
on Nov 29, 2018 02:31 AM
13962 Views

Hi ,

I have a table Payment

PaymentID PaymentDate Medicare Medicaid VA
1 8 30 20 5
2 9 30 20 5
3 10 29 20 6
4 11 29 19 6

and a stored procedure for this table

SELECT Pay_Number, d8 as '8',d9 as '9',d10 as '10', 
d11 as '11'
FROM (SELECT [PaymentDate], Amount, Pay_Number 
FROM (SELECT 'd'+ Convert (Char(10), [PaymentDate], 112) as [PaymentDate], 
[Medicare]
,[Medicaid]
,[VA]
FROM [VDS].[dbo].[Payment]) as sq_source
UNPIVOT (Amount FOR Pay_Number IN
([Medicare]
,[Medicaid]
,[VA])) as sq_up
) as sq 
PIVOT (
MIN(Amount)
FOR [PaymentDate] IN
(d8, d9, d10, d11)
) as p;

This stored procedure is used to transpose the column to rows and rows to column like the below,

Medicaid 20 20 20 19
Medicare 30 30 29 29
VA 5 5 6 6

When I tried to connect this stored procedure with my MVC code using Entity framework I am getting the following error

"System.Data.Entity.Core.EntityCommandExecutionException: 'The data reader is incompatible with the specified 'VDSModel.F_MBU_GYNew_NormConc'. A member of the type, 'NormID', does not have a corresponding column in the data reader with the same name.'"

"System.Data.Entity.Core.EntityCommandExecutionException: 'The data reader is incompatible with the specified 'VDSModel.Payment'. A member of the type, 'PaymentID', does not have a corresponding column in the data

 

thanks,

R

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Nov 29, 2018 06:45 AM

Hi Rockstar8,

Consider the case that might be the reason for the error.

One of the columns being returned from the stored procedure is not in the class that it is being populated.

For example the data reader has a column called "Name" but the class in your code does not have a property called "Name" or the reader has a column named "Name" but the class object being filled has the property "FirstName" which does not match "Name". Look for a missing column in your class or not spelled the same way.

The recordset being returned had a different column name than the one defined in the entity.

If this will not resolve your issue please share your code and procedure.

Rockstar8
 
on Dec 10, 2018 02:21 AM

Thanks for the reply but the mistake is mine since I am using Pivot table my values will be my column name which won't match with my table columns.