Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8042057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:26:34+00:00 2026-06-05T04:26:34+00:00

I want to programmatically create the database create script for my EF 4.3 Code-First

  • 0

I want to programmatically create the database create script for my EF 4.3 Code-First database. The database creates just fine using the standard DatabaseInitializer mechanisms, but the following code fails:

using(var dc = new MyContext())
{
    var objContext = (IObjectContextAdapter)dc;
    var script = objContext.ObjectContext.CreateDatabaseScript();
}

The exception I get is:

The store generated pattern ‘Computed’ is not supported for properties that are not of type ‘timestamp’ or ‘rowversion’.

I do have a Computed column defined of type “string” but like i said, the database creates fine when created via the built-in DatabaseInitializer. Oddly enough, the resulting schema using this method doesn’t actually create a computed column.

As to why I’m doing this, I have a script that runs post-create that drops this column and creates a bonafide computed column. Without specifying the column as computed in the EF mapping, it will attempt to assign that column a value upon inserts, which then fails.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:26:36+00:00Added an answer on June 5, 2026 at 4:26 am

    Leaving database creation aside for a moment, setting “Computed” means that EF will not attempt to write the value of that column but will read the value that was (presumably) computer by the server each time the column is queried. From an EF perspective it is valid to have a computed column for any data type.

    Now consider database creation from the EF model. EF doesn’t know what to do to create the computed column in the database, and indeed it may not even be possible to do it without triggers in certain databases depending on the type of the column. So in EF4 the decision was made to make CreateDatabaseScript throw in these situations.

    However, EF 4.3 and later don’t use CreateDatabaseScript anymore when targeting SQL Server or SQL Server Compact. They instead use the Migrations pipeline. For the Migrations pipeline we decided to take a different approach because we felt that it was wrong for database creation to always throw for what could be a perfectly valid model. Especially considering you could have written your own SQL in the migration that added a trigger or some other mechanism to make the database create a valid computed column.

    So this is why you see the database being created by EF 4.3 (but without doing anything to make the column computed) but then you see the same model throw when trying to use CreateDatabaseScript which uses the older, non-Migrations mechanisms.

    The way to fix this is to have Migrations create the scripts instead of using CreateDatabaseScript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to programmatically create a directory on the server using ASP.NET. I have
I want to programmatically modify a bitmap using python but don't really need a
I want to programmatically create a new log4j ConsoleAppender and add it as an
I want to create a webpart programmatically like below to contain fixed links to
I created a UIButton programmatically and I want to create an action to handle
How do I programmatically create buttons with images on them. I want to store
I'm using ASP.NET MVC 3 code-first and I have added validation data annotations to
I'm creating a SQL CE database file programmatically and want to make sure I'm
Is it possible to programmatically create input events in c#. I want to be
Can I programatically(or whichever way works fine) create the backup of a database, with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.