none
Adding EF to ASP.NET Core 3 app RRS feed

  • Question

  • I'm trying to write a CRUD API project which uses EF Core.. Found the article at 

    https://dzone.com/articles/aspnet-core-crud-with-reactjs-and-entity-framework

    When I get to the Scaffold -DbContext step - i run:

    PM> Scaffold-DbContext "Data Source=MSQL01-DEV-FRA;Initial Catalog=ENT_SHIFT_HANDOVER;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables

    And get the following error:

     

    Scaffold-DbContext : Missing an argument for parameter 'Tables'. Specify a parameter of type 
    'System.String[]' and try again.
    At line:1 char:167
    + ... ue" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables
    +                                                                   ~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Scaffold-DbContext], ParameterBindingException
        + FullyQualifiedErrorId : MissingArgument,Scaffold-DbContext

    Any ideas how to get around this - i'm used to adding an EF project more by automated tool.  Trying to add EF model from database on another server.

    Friday, January 3, 2020 8:13 PM

Answers

  • I think the link clearly shows how to scaffold EF core for an existing database.

    https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx

    The link talks about the EF Core tools and in particular what -Tables parameter is about in Scaffolding the Dbcontext. 

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

    EF can be discussed at the EF forums.

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework

    https://forums.asp.net/1227.aspx/1?ADO+NET+Entity+Framework+LINQ+to+SQL+NHibernate


    • Edited by DA924x Friday, January 3, 2020 9:55 PM
    • Marked as answer by Mimosa Arts Saturday, January 4, 2020 4:21 AM
    Friday, January 3, 2020 9:53 PM

All replies

  • By default all tables are done without using -table or -t

    https://docs.microsoft.com/en-us/ef/core/managing-schemas/scaffolding#specifying-tables

    Here -t is for tables that are a subset, did this with a wizard I wrote.

    Scaffold-DbContext "Server=.\SQLEXPRESS;Database=NorthWindAzureForInserts;Trusted_Connection=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context NorthWindAzureForInsertsContext  -v -f  -project NorthWind.Data -startupproject NorthWind.Data -ContextDir Context -t "Contacts","ContactType","Countries","Customers","Employees"

    See also a Visual Studio add in for reverse engineering

    https://github.com/ErikEJ/EFCorePowerTools/wiki


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Friday, January 3, 2020 8:43 PM
    Moderator
  • I think the link clearly shows how to scaffold EF core for an existing database.

    https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx

    The link talks about the EF Core tools and in particular what -Tables parameter is about in Scaffolding the Dbcontext. 

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

    EF can be discussed at the EF forums.

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework

    https://forums.asp.net/1227.aspx/1?ADO+NET+Entity+Framework+LINQ+to+SQL+NHibernate


    • Edited by DA924x Friday, January 3, 2020 9:55 PM
    • Marked as answer by Mimosa Arts Saturday, January 4, 2020 4:21 AM
    Friday, January 3, 2020 9:53 PM