none
How to Update the C# code when you have added a new table or stored procedure? RRS feed

All replies

  • Hi,

    Sorry, I could not fully understand your question. Could you explain it in detail? Do you mean the situation that create a new table? Maybe you can refer to this document: Getting Started with EF Core on ASP.NET Core with a New database.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 10, 2019 6:33 AM
    Moderator
  • https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db?toc=/aspnet/core/toc.json&bc=/aspnet/core/breadcrumb/toc.json&view=aspnetcore-2.2

    I have followed this instruction above and it works. I have the database and the c# code.

    The next phase is that I add a new table named test

    Table: test

    Column: Testid (int), testname (nvarchar(50))

    This test table is added in the database.

    The code "Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models" enable you to create the class and its data member from scratch but this time I have added a new table.

    The code "The code "Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models"" do not work in relation to maintenance when I have added a new table.

    The main question:

    What code in powershell or something similiar  should I use in order to update the current c# codel in relation to entitiy frame core?

    I need to have c# code for the table "Test" in VS solution.

    Please inform me if you need more instruction or explaination.

    Thank you!

    Friday, May 10, 2019 10:07 AM
  • https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db?toc=/aspnet/core/toc.json&bc=/aspnet/core/breadcrumb/toc.json&view=aspnetcore-2.2

    I have followed this instruction above and it works. I have the database and the C# code.

    The next phase is that I add a new table named test

    • Table: test
    • Columns: Testid (int), testname (nvarchar(50))

    This test table is added in the database.

    The code

    Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

    enables you to create the class and its data member from scratch but this time I have added a new table.

    The code

    Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
    does not work in relation to maintenance when I have added a new table.

    The main question:

    What code in PowerShell or something similar should I use in order to update the current C# code in relation to Entity Framework Core?

    I need to have c# code for the table "Test" in VS solution.

    Thank you!

    Saturday, May 11, 2019 8:26 AM
  • I don't know.  However in using EF Core DB first approach, I can go to the database using SSMS and add a new table or make changes to an existing table and Scaffold out a  new Model. Now one would assume the Scaffold 'Output' command if pointing to the hard-drive on the developer's machine  where the existing DB.Model is located, it would wipe it out and make a new DB.Model with the changes.

    I don't know that to be a fact that the old DB.Model would be wiped out with new DB.Model that was created.  Or you could Scaffold out the DB.Model to a new folder not related to the VS project's DB.Model and manually systematically incorporate the changes to the old DB.Model form the new one you have in the other folder. Myself, I would just take to newly created DB Model and replaced the old one.

    But one the other hand, one wouldn't want the existing DB.Model replaced if the DB.Model had special coding in it.  I'll tell you what I have done is made changes to the database using SSMS, and just manually updated the existing  DB.Model code myself, like added new tables,  made table changes  or whatnot directly in the code myself and went on about my business.

    However, check this it and see if this is a viable option with EF Core.

    https://github.com/aspnet/EntityFrameworkCore/issues/831

    You're probably going to have to  develop a PowerShell script of your own  or search the Internet using Bing or Google for a solution.

    There is this EF Core Power tools thing too.

    https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools


    • Edited by DA924x Saturday, May 11, 2019 2:58 PM
    Saturday, May 11, 2019 2:53 PM