1

I'm working with EF5 using the model-first approach. I've designed the model and executed the SQL script which generated the corresponding database (using "Generate Database from Model").

I then had to use UDFs to calculate a couple of column values (which requires dropping and re-adding the columns). I've done that in SSMS and then used "Update Model from Database..." to reflect the changes in the model.

Till this point, everything worked great.

But from this point, every time I update the database from the model (as described above), the computed columns are overridden with "standard" columns.

For example, following is an excerpt from the SQL script generated by EF:

-- Creating table 'ShipmentSet'
CREATE TABLE [dbo].[ShipmentSet] (
[Id] int IDENTITY(1,1) NOT NULL,
[Details] nvarchar(128)  NOT NULL,
[BarcodeValue] nvarchar(32)  NOT NULL,
[ExecutionDate] datetime  NOT NULL,
[RouteId] int  NOT NULL,
[IsLocationBarcodeRequired] bit  NOT NULL,
[IsPending] bit  NULL,
[LastAction] tinyint  NULL
);
GO

The two last columns are computed columns, and their StoreGeneratedPattern in the model is defined as Computed.

Is there a way to add the computed column formulas in the model? The SQL script drops the tables then re-creates them, so "ignoring" these columns won't do.

ury
  • 1,050
  • 11
  • 22

1 Answers1

0

I got the following response from Microsoft's developer center (see full thread here)

Essentially the answer is that it's not a bug, it's simply not supported:

You can't mix model-first and database-first. Once you manually modify database you can't use Generate database from EDMX any more. UDF-based computed columns information are stored in SSDL, CSDL know nothing about it, so everytime you generate the database from EDMX file, the special columns will be generated as regular columns.

So if you want to use computed columns and UDFs, Database-first is the only choice for you.

I can't say I'm satisfied with the answer, as it means EF Model-first is useless for the most of my projects, but that's just the way things are.

Any comments are welcome.

ury
  • 1,050
  • 11
  • 22