views:

43

answers:

1

Using VS2010 and .NET 4 what exactly does the ADO.NET EF wizard update when you right click in the EF model and select Update from database because I have a feeling that very little.

For instance, making a column optional (null values allowed) in SQL Server Management (a value that was previously not nullable) and updating the model in VS, does not change that entity property to Nullable = true. It remains false. That's just one example but I think there's more, like column lengths changes etc.

+1  A: 

The .edmx file that is your Entity Framework model is actually an XML-based file that contains (primarily) three separate sections:

  1. A "storage model" that contains data about the database itself.
  2. A "conceptual model" that defines the entities in your application.
  3. A mapping between #1 and #2.

Empirically, I have determined that the 'update from database' process will add, remove, or modify anything in the storage model that appears to be inconsistent with the current database schema. On the other hand, it will not modify or remove anything in the conceptual model (it will add stuff, though).

This makes sense because there is not necessarily a 1-1 correspondence between entities (and their properties) in your application and tables (and their fields) in the database.

Daniel Pratt
so, in a sense, this means that we have to drop/recreate the EDMX each and every time we make changes to the database model, if we want them to be identical, and in our simple case, we do want that. There's no reason why one property should be nullable in conceptual model and notnullable in storage model.
mare
Maybe you'd be happier with LINQ-to-SQL? Although I have no real experience with LINQ-to-SQL, I do know that it is intended to maintain pretty much a 1-1 mapping between the database schema and the entities in your app.
Daniel Pratt
+1 - yes, the VS built-in "update from database" wizard updates the SSDL and brings _some_ SSDL-to-CSDL difference across to the CSDL. Other changes are left untouched. Additionally, if you make changes in the designer you are updating the CSDL. Only some types of changes (e.g. removed entities) are reflected across to the SSDL, while other changes made in the designer can/will lead to the SSDL and CSDL getting out of sync.
KristoferA - Huagati.com