This project is read-only.


Generate database from model does not work for views.


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">
    [vChainSubscriptions].[ChainName] AS [ChainName], 
    [vChainSubscriptions].[ChainActive] AS [ChainActive], 
    [vChainSubscriptions].[Changed] AS [Changed], 
    [vChainSubscriptions].[ChangedBy] AS [ChangedBy]
    FROM [dbo].[vChainSubscriptions] AS [vChainSubscriptions]</DefiningQuery>
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 29, 2014 at 12:17 AM 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.


davekolb wrote May 27, 2014 at 8: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.