0

All commands I know like:

var t = _context.Database.GenerateCreateScript();

Add-Migration 
Script-Migration

starts script from "Create table" command.

  1. So.... what decides about database name(connection string I know) and how database is created by EF Core?
  2. Why 'Create Database' is not in the scripts?
  3. How to generate SQL script to use without Entity Framework - is it possible?
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Artur
  • 95
  • 9
  • Does this answer your question? [Can I generate script of a migration with EF code first and .net core](https://stackoverflow.com/questions/39644544/can-i-generate-script-of-a-migration-with-ef-code-first-and-net-core) – Gert Arnold May 15 '23 at 10:53

1 Answers1

1

It's best to create the database before running the script. There are several reasons for this.

  1. Not all database systems are capable of creating catalogs (aka databases) from a script.
  2. Creating databases from the script requires additional permissions that you may not have.
  3. There are several options available when creating a new database and one size does not fit all. For example, when creating a cloud database, you probably want the person running the script to think about which pricing plan they're signing up for.
bricelam
  • 28,825
  • 9
  • 92
  • 117
  • it is an idea. Thanks :) So maybe you have an idea about how to define computed column with UserFunction which does not exist in db when it is created by EF while context.ensureCreated? Is there any out of the box EF solution or manually script modification in migration ? https://stackoverflow.com/questions/76172525/entity-framework-core-creating-db-hascomputedcollumn-with-user-function-how-to-c – Artur May 16 '23 at 06:26