Column added to view not getting picked up by Entity Framework?

I added a new column MyColumn to vwMyView in MyDB. MyDB has a stored procedure MySproc which returns vwMyView.* in a select statement.

When I execute MySproc, vwMyView.MyColumn is included in the result set. However, when I recreate my EF6 .edmx data model, MyColumn is not reflected in the EF vwMyView object or in MySproc_Result.

Is there a special trick I need to use so my new column MyColumn is reflected in a recreated EF6 .edmx? Is this a quirk that you encounter sometimes?

1 answer

  • answered 2018-04-17 04:15 NitinSingh

    Happens sometimes, especially when the output is generated runtime as a polymorphic behavior (different result sets based on conditions)

    In EF, for a result set, you may need to explictly create an output mapping. No need to delete the whole EDMX, just select the mapping (MySproc_Result) and update the result set to include the new column.

    Are you creating the view inside procedure and then returning its value?

    Inside the view, check if the columns are added conditionally (eg, if type=Sales, include 4 columns, if type=Mgmt, include 5 columns). The EF will pick up the 1st matching case in this condition.

    Best way is to update the mapping and have the new column set as nullable, just in case some conditional makes it unavailable.