none
How to exclude 2 tables out of 120 tables in EF Core DB First approach RRS feed

  • Question

  • How to exclude 2 tables out of 120 tables because those two tables are not going to use in my application and those two tables do not have primary key that is why it is throwing an exception. Those two tables will be used by SQL Jobs in the back end. We need to have those two tables but do not have to generate models for those two tables.

    I know one thing that is Scaffold-DbContext can include tables by using --table command we can pass entities as string array but that is not that much good practice for me because I have to include approximately 120 tables every time whenever my DB has DDL changes.

    Thanks in advance!


    Monday, January 13, 2020 7:41 PM

Answers

  • You can use EF Core Power Tools!

    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    Monday, January 13, 2020 8:45 PM
  • You can scaflod the model with the tables you want by using the Tables parameter.

    https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

    Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables "Blog","Post" -ContextDir Context -Context BlogContext

    Monday, January 13, 2020 11:44 PM

All replies

  • You can use EF Core Power Tools!

    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    Monday, January 13, 2020 8:45 PM
  • You can scaflod the model with the tables you want by using the Tables parameter.

    https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

    Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables "Blog","Post" -ContextDir Context -Context BlogContext

    Monday, January 13, 2020 11:44 PM
  •  Dear ErikEJ,

     Thank you so much for your reply.. Actually I am using VS Code so  how to solve my problem?

    Thursday, January 16, 2020 10:38 AM
  • Hi Dear,

     As you said we can do this -Tables "Blog", "Post" but I have to include approximately 120 tables every time whenever my DB has DDL changes.

    Thursday, January 16, 2020 10:41 AM
  • Install Visual Studio?


    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    Thursday, January 16, 2020 12:18 PM
  • Dear ErikEJ,

    EF Core Power Tool is fixed my issue only in Visual Studio not in VS CODE but I am using only VS CODE.

    if you have any solution for VS CODE also please tell me or else i can mark it as answer.

    Thursday, January 16, 2020 2:27 PM
  • Hi Dear,

     As you said we can do this -Tables "Blog", "Post" but I have to include approximately 120 tables every time whenever my DB has DDL changes.

    You have to think out side the box sometimes by scaffolding the dbcontext that is string data at the .NET Core  command prompt or the Nuget package manager command prompt and save it in a text file using notepad. You can open the text file with notepad and copy/paste  the text file content of the dbcontext scaffolding command, paste it to the command line and execute the command. 

    How hard can it be? :)


    • Edited by DA924x Thursday, January 16, 2020 3:31 PM
    Thursday, January 16, 2020 3:30 PM
  • Dear DA924x,

    Yes, you are right! As you said we can copy the whole string in a separate text file and we can paste it in the command line whenever it is needed but all users may not have less than or equal to 120 tables  in my case it will be okay to prepare a string for the first time. If one has more than 1000 tables in this case it is hard to prepare a string for the first time also because it will take more amount of time that is why i am actually expecting is there anything like Exclude command. Thanks for your time.

    Friday, January 17, 2020 10:54 AM
  • Dear DA924x,

    Yes, you are right! As you said we can copy the whole string in a separate text file and we can paste it in the command line whenever it is needed but all users may not have less than or equal to 120 tables  in my case it will be okay to prepare a string for the first time. If one has more than 1000 tables in this case it is hard to prepare a string for the first time also because it will take more amount of time that is why i am actually expecting is there anything like Exclude command. Thanks for your time.

    1,000 tables used in a single Dbcontext is ridiculous,  and the solution would be slowed every time the context was instanced.  
    Friday, January 17, 2020 4:44 PM
  • okay, can single DbContext handle how many tables without any performance issues? 
    Friday, January 17, 2020 5:56 PM
  • okay, can single DbContext handle how many tables without any performance issues? 
    IMO, 100 tables on a single Dbcontext is pushing it particularly in a multi user environment where the context is being instanced multiple times in a user session.
    Saturday, January 18, 2020 12:10 AM
  • okay
    Monday, January 20, 2020 11:45 AM