Reputation: 1829
I have already created the initial asp.net mvc web application template in visual studio code. And I can run the application in a browser at localhost:5000/ I can also see the views, controllers, viewmodels like the previous asp.net mvc core.
Now, how can I install and use entity framework core using visual studio code?
Thanks.
Upvotes: 19
Views: 61869
Reputation: 736
1st : You need three line of code to install EntityFrameWork core and its dependencies.
2nd : install them in this form
dotnet add package Microsoft.EntityFrameworkCore -v 2.1.14
dotnet add package Microsoft.EntityFrameworkCore.tools -v 2.1.14
dotnet add package Microsoft.EntityFrameworkCore.SqlServer -v 2.1.14
I put a sample of them with version but you can get latest entityframework version if you remove version in last of line. like this.
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.tools
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
3rd
Remember your .Net Core version should be compatible with lastest version of EntityFrameWork core which you want to install.So if you have error either you have to install lastet version of .Net Core or install EntityFrameWork core with a compatible version with .Net Core.
Probably you are looking for EntityFrameWork core version here and also for .net Core version here
Upvotes: 14
Reputation: 617
You can use Nuget Package Manager extension. After installing extension;
After selecting, it will add necesassary PackageReference to .csproj file.
Upvotes: 1
Reputation: 21
In my case i had deleted the "csproj" by accident, after research a lot, i knew about this possibility and found the deleted file in my trash.
Upvotes: 0
Reputation: 26763
VS Code is just an editor. It doesn't install EF (or any packages). You can install EF by editing your csproj file to contain this set of lines.
<ItemGroup>
<PackageGroup Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
</ItemGroup>
VS Code may give you a prompt to "restore" pacakges. If not, call dotnet restore
on command line.
Alternatively, on command line you can execute:
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
See the "Getting Started" guide for more details on EF. To use EF, you need to write code. A full example is beyond the scope of a good StackOverflow answer and is subject to change as EF Core continually updates.
Upvotes: 28
Reputation: 465
In addition to answers given above, following article has all the steps for adding EF Core using .Net Core CLI.
Hope this helps to someone.
*Edit: - VS Code users can execute dotnet commands from Terminal window (Ctrl+Shift+`)
Upvotes: 3
Reputation: 4338
To be able to use entity framework in visual code you can use yeoman on the terminal:
>npm install -g yo
>npm install -g generator-efrepo
>yo efrepo
Then follow the instructions
Upvotes: 4
Reputation: 19
I think this is the updated link, as of June 3.
https://docs.efproject.net/en/latest/
Upvotes: 1