views:

109

answers:

4

In my Entity Framework v4 project, I have a table with two columns that are computed by the database (via triggers, etc.). In order to get EF to properly insert records into the table, I have to manually mark the columns as "Computed" in the EF Storage Model (the StoreGeneratedPattern attribute), which is not supported by the designer -- so I have to make the edits by hand to the XML in the .EDMX file.

The problem is that whenever my database schema changes, and I need to update the storage model in my project, the "Update Model Wizard" overwrites the whole Storage Model section of the .EDMX, eliminating my manual changes. This means that I have to keep a special list of such changes and manually re-apply them EVERY TIME I do an update! For the love of god, this has got to be one of the dumbest glitches in EF.

Anyway, my question for the hive is this... Is there any way to prevent the Storage Model overwrites? Is there a way to flag the columns in the database, so that EF will automatically mark them as computed? As a last resort, is the some REALLY EASY XML tool/technique that can automatically apply the changes for me after every refresh?

THANK YOU, oh learned StackOverflow contributors for easing my pain and helping me with this problem even though I do not yet have any status on the site. Someday, when I have a 4+ digit reputation, I will remember you.

Brian


Update

I've been told by an insider that one solution might be to check out the "Designer Power Pack" (link below), which allows you to customize generation of the storage model. I've only skimmed the info so far, but it looks to me like there may be a day or two learning curve to figure that out. Does anyone have any experience with the Designer Power Pack, or any other ideas?

http://blogs.msdn.com/b/adonet/archive/2010/02/08/entity-designer-database-generation-power-pack.aspx

Thanks again, Brian

A: 

Taking a shot in the dark here, but have you considered using a View for the table - minus the two computed columns - and not adding the table to your model?

BradBrening
That's a good idea for a workaround, which I may explore if necessary. Not sure if the resulting view will allow for inserts/edits, as it would be composed of at least two tables. That configuration would also defeat the raison d'etre of EF and be more like LINQtoSQL.
BrianFinkel
+1  A: 

According to the EF team at Microsoft, this is currently their biggest complaint from customers and also their highest-priority bug.

They say they have a solution designed and plan to ship it with the next release of Visual Studio, likely VS 2010 SP1, but no date on that.

Unfortunately, no good workaround has come up from any sources, but I'm still open to ideas!

Brian

BrianFinkel
A: 

I just released a tool that may help you: a 'model comparer' for EFv4 models. It is part of my add-in package Huagati DBML/EDMX Tools for Visual Studio, and shows differences between the database, SSDL, and CSDL layers. You can select individual differences and bring them across to the opposite layer(s), or add differences you don't want to bring across to the ignore list.

When bringing changes across, it only updates the affected portions of the model; unrelated and unchanged portions remain untouched.

You can download it and get a trial license from http://huagati.com/dbmltools/ if you want to try it out.

Huagati EDMX Tools Model Comparer for EFv4

KristoferA - Huagati.com
Will your tool update the storage model from the current database schema? If not, I'm not sure how it helps. The problem is that manual changes to the storage model, which are required for my setup to work, are overwritten whenever the storage model is updated.
BrianFinkel
Yes, it compares the current db schema with the storage model, the storage model with the conceptual model, and shows differences. It then allows you to select what differences you want to bring across and what differences you want to leave in place. Unlike the VS built-in "update model" wizard it only touches the parts of the model that you choose to update, leaving everything else in place. I posted a short intro screencast on my blog yesterday that shows some of the basic features: http://huagati.blogspot.com/2010/07/introducing-model-comparer-for-entity.html
KristoferA - Huagati.com
A: 

You could generate your edmx file using an alternative designer such as the one in LlblGenPro v3.0. Off the top of my head I don't know how well it supports calculated columns. But if you ask in the support forums http://www.llblgen.com/tinyforum/ you will get a quick, accurate answer. If by chance this feature isn't supported, it's possible that they can add it in a upcoming release. Their delivery cycle is much shorter than MS's.

By the way the LlblGenPro designer not only supports Entity Framework v4 and V1 but NHibernate, Linq to Sql, and their own LlblGenPro runtime.

automatic