views:

34

answers:

1

Hi,

We're using a Function Import in an EF4 model to populate an existing entity in our Model. The entity in the model has a Key field of Id which we're struggling to map as our stored procedure doesn't return an Id field. I've tried setting the value in the mapping to a literal value of 0 but that fails with an EntityCommandExecutionException and the following exception text.

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

Short of modifying the stored procedure to return a dummy Id field can anyone recommend what the best approach is for this as the dummy field option feels very clunky to me.

Many Thanks

A: 

If you can't return enough data to fully materialize the entity -- and the Id field is certainly going to be required for that -- then you need to change the return type on the proc to be a complex type instead of an entity.

Craig Stuntz
Thanks for the response Craig. What we're essentially trying to do is add a Candidate to the Context just from a different DB table so by mapping directly to the stored proc and function import it saves us having to map from the complex type returned by the function to the Candidate entity in code.If that's what we have to do then that's OK but it seems strange that the EF will allow me to bind to the Candidate entity when it knows the return schema of the sp and therefore knows its never going to work out against the Candidate. This is what led me to believe we're missing something.
Daz Lewis

related questions