How to use Entity Framework to map results of a stored procedure to entity with differently named parameters

From Entity Framework Code First book (page 155):

The SQLQuery method always attempts the column-to-property matching based on property name…
None that the column-to-property name matching does not take any mapping into account. For example, if you had mapped the DestinationId property to a column called Id in the Destination table, the SqlQuery method would not use this mapping.

So you cannot use mappings when calling stored procedure. One workaround is to modify your stored procedure to return result with aliases for each column that will match your object properties’ names.

Select UT_STR_AD as Address From SomeTable etc

Leave a Comment