1

Closed

Generate database from model does not work for views.

description

If I create or update a model from a database, I get a defining query like below.
          <EntitySet Name="vChainSubscriptions" EntityType="Self.vChainSubscriptions" store:Type="Views" store:Schema="dbo">
            <DefiningQuery>SELECT 
    [vChainSubscriptions].[ChainName] AS [ChainName], 
    [vChainSubscriptions].[ChainActive] AS [ChainActive], 
    [vChainSubscriptions].[Changed] AS [Changed], 
    [vChainSubscriptions].[ChangedBy] AS [ChangedBy]
    FROM [dbo].[vChainSubscriptions] AS [vChainSubscriptions]</DefiningQuery>
          </EntitySet>
Then after some model changes, I want to "generate database from model" to create a new temp database so I can compare to the old database, and my view is turned into a table!
    <EntitySet Name="vChainSubscriptions" EntityType="TxData.Store.vChainSubscriptions" store:Type="Tables" Schema="dbo" />
How can I prevent this bad behavior? Generate model from database back to model should round trip not change a query to a table.

Thanks, Dave
Closed May 28 at 11:17 PM by RoMiller
EF Team Triage: This is by design. The 'Generate database from model...' process only looks at the shape in the conceptual part of the model (basically the shape of your entities and relationships) and then generates the mapping and storage layer from scratch based on that information.

comments

davekolb wrote May 27 at 7:04 PM

To be clear, the generated sql script for the new database should add the view definition to the new database.

Also would be nice if something more sane was done with the key for a view rather than trying to make a super key out of every column since EF should know this is a view and all the columns make an illegal key when too many columns of too large size.