locked
How to create a table in to the existing database using EF RRS feed

  • Question

  • User-1355965324 posted

    I dont know I am asking stupid question  if so please sorry

    I just created model into the existing  context. Is it possible to  create a new table in to the existing database using that new model in context , without running migrate entire object

     please can you let me know.

    Pol

    Friday, September 18, 2020 11:55 AM

Answers

  • User1312693872 posted

    Hi,polachan

    polachan

    Is it possible to  create a new table in to the existing database using that new model in context , without running migrate entire object

    If you want to create a table, you can manually use sql sentence to create it in SQL Server Object Explorer.

    The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's data model while preserving existing data in the database.

    If you want to use it in your project,use add-migration at least in either code first or database first approach will be better.

    Best Regards,

    Jerry Cai

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 21, 2020 2:53 AM

All replies

  • User753101303 posted

    Hi,

    Not 100% clear. With EF you have basically two approach ie :
    - "code first" :  you are writing C# describing db entities and EF creates/updates the database for you
    - "code first from database", "scaffolding" : you start from the database and EF generates the corresponding C# code for you

    Or finally you take the whole control and both update the db and the code yourself if you really want. For  now it's unclear if you have a problem with your current approach and you wan't to switch?

    Edit: or do you mean you want to create a table inside your database without exposing it through EF ?

    Edit 2: if new to EF Core start maybe with https://docs.microsoft.com/en-us/ef/core/managing-schemas/

    Friday, September 18, 2020 12:10 PM
  • User1120430333 posted

    Why can't you use SSMS and create the table via the DBA tool?

    Friday, September 18, 2020 12:11 PM
  • User475983607 posted

    I dont know I am asking stupid question  if so please sorry

    I just created model into the existing  context. Is it possible to  create a new table in to the existing database using that new model in context , without running migrate entire object

     please can you let me know.

    Yeah that's how migrations work!!!   The process finds the changes since the last migration and created migration file.  If you made changes other than the new model/table and don't want those changes in the DB then you are not using the technology correctly.  

    Friday, September 18, 2020 12:21 PM
  • User1312693872 posted

    Hi,polachan

    polachan

    Is it possible to  create a new table in to the existing database using that new model in context , without running migrate entire object

    If you want to create a table, you can manually use sql sentence to create it in SQL Server Object Explorer.

    The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's data model while preserving existing data in the database.

    If you want to use it in your project,use add-migration at least in either code first or database first approach will be better.

    Best Regards,

    Jerry Cai

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 21, 2020 2:53 AM