Try using
dnx ef dbcontext scaffold "Server=Server\InstanceName;Database=db;Trusted_Connection=True;" EntityFramework.MicrosoftSqlServer --dataAnnotations --outputDir Data --verbose --table dbo.Users
All the above parameters should be on one line, but I wrapped a long line to read it more easily. You can look at the source code to see which options support the scaffold command in RC1.
Be careful with copying and pasting ConnectionString from appsettings.json , because you may have Server=Server\\InstanceName; in ConnectionString , but dnx ef dbcontext scaffold now only accepts Server=Server\InstanceName; and you will get a System.InvalidOperationException error when using Server=Server\\InstanceName; copied directly from ConnectionString from appsettings.json .
An additional important parameter is -p | --targetProject -p | --targetProject , which is important if you use the repository in the class library. In case you define the ef command in the main project and run dnx ef dbcontext scaffold in the main project directory, but use -p to refer to the class library project.
Last remark. Sometimes you need to tint a subset of tables from a database. This is not completely clear from the command line help, but you can specify the -t ( -table ) -table several times . See the note on the wiki EF7. Thus, if you want to import only two tables, dbo.Users and dbo.Posts (regardless of whether Posts foreign key for Users ), you can use the following syntax
dnx ef dbcontext scaffold "Server=Server\InstanceName;Database=db;Trusted_Connection=True;" EntityFramework.MicrosoftSqlServer -a -o Models -v -t dbo.Users -t dbo.Posts
UPDATED: In ASP.NET Core RC2 and later, you should use dotnet ef dbcontext scaffold instead of dnx ef dbcontext scaffold .
source share