Schroedingers Cat
Schroedingers Cat

Reputation: 3129

Entity Framework 5 Data mapping

I have mapped a complex type to the results of a SP, and am getting the following error:

The data reader is incompatible with the specified 'CLMModel.GetContractPerformanceReview_Result'. A member of the type, 'LastYearProfit', does not have a corresponding column in the data reader with the same name.

I know that this normally indicates something wrong in the mapped types, so I have looked and tweaked them to no avail. The incoming type is a decimal(18, 2) (on SQL Server), and the mapped type is also decimal(18, 2). I have tried increasing the precision to 38,2 without success, as I thought it may be a case of a potentially larger values being detected.

The value is generated from a column, with this definition, so I can see no reason that it would not map successfully.

I have even tried Create a new Complex Type, to use a generated type, but it still fails. I have confirmed that the field names match too.

Ad assistance would be much appreciated. I have tried searching for this on SO, without success, but if there is another question you can point me to, please do. Thank you.

Upvotes: 1

Views: 161

Answers (1)

Schroedingers Cat
Schroedingers Cat

Reputation: 3129

OK, I have found the cause of this, which is that the Stored Procedure that generates this response created different results sets depending on the parameters. This meant that when I ran it manually, it showed the columns, but the entity framework could not correctly identify the correct columns.

So the lesson is - if your SP returns different results for different parameters, make sure that they all return the same columns.

Upvotes: 1

Related Questions