I am new to .NET core. Trying to get used to it. But its kind of complicated.
I have my poco classes in 'solution.Entity' library project and I want to use them to create a database with EF code first in my 'solution.Data' library project.
But when I try to install Entity Framework via Nuget to my 'solution.Data' project it says 'Package Restore Failed. Rolling back...'
Both projects are .NET Core Library projects.
What do I need to do to be able to use EF in .NET core library projects? It's look like I need some kind of configuration.
Thanks for helps.
Make sure you're installing EF Core. .NET Core has it's own implementation of Entity Framework.
This should be the NuGet package you're installing.
There are lots of pieces to getting Entity Framework Core working right. I highly recommend taking a look at the docs. There are dozens of samples that show how to setup a project.
https://github.com/aspnet/EntityFramework.Docs
http://learn.microsoft.com/ef/
In particular, I suggest this guide. It will talk you how to take your POCO classes and make a database in a .NET Core project. You will likely find it easiest to keep.everything in one project for now and move code into separate libraries once you get more familiar with EF.
Related
How can I add a reference of a .Net Core 2.0 project into my .Net 46 project?
My project is structured as follow:
Solution
- Data Project (.Net Core 2.0)
- Test Project (.Net 46)
I'm trying to reference the Data Project into my Test Project as I need to insert some data using it. The only reason I created a .Net Core 2.0 is that I'm trying to use Entity Framework on Visual Studio for Mac and it didn't work using the "normal" Entity Framework nuget package, so I opted for the EntityFrameworkCore.
I was able to manually reference the Data Project dll, but then when I run a test I get the message
"Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.0.0. Culture=neutral' or one of its dependencies"
Is there any solution for this? If not, what's the best way to work with Visual Studio on Mac and Sql Server when you need to retrieve and insert data? Would Dapper work?
Thanks
What you asked is impossible.
.NET Framework projects can only consume .NET Standard Class Library projects, but not .NET Core projects.
See the reference for more information,
https://blog.lextudio.com/which-class-library-project-to-go-in-visual-studio-2015-2017-a48710cf3dff
I would expect some kind of filter to exists on website or in console.
This isn't easy right now, unfortunately. There's an issue open on the NuGet Github about adding a filter to the website.
Right now, the best way to tell if a package will work with .NET Core is by examining the frameworks it supports in the Dependencies section.
If .NETStandard is listed, the package supports .NET Core via the .NET Platform Standard:
If a package's Dependencies section doesn't mention .NETStandard, or the Dependencies section is completely empty, it does not support .NET Core:
Setup a .NET Core project in the version you want. I keep 1.1 and 2.0 projects around for futzing with this. Then try and add the nuget to the project.
For instance, ASPOSE will NOT add to a 1.1 project, but will add to a 2.0 project.
Easiest route in the short term until they fix this somehow.
Obviously this is no guarantee it still works but gives you a good idea if its api compat.
I am porting a project from MVC 5 to MVC 6. My project has two components the MVC application itself and a assembly that has all of the database code in it, including all db models, and the DbContext.
In the assembly I modified the project.json to have the ef commands dll and removed it from the MVC project.json. I have ported over all of my models, etc. and the application is compiling without errors. I want to execute
dnx ef migrations add
from a command shell in the subdirectory of the assembly in the project. When I do that I get
No DbContext was found. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
What is the correct way to accomplish this type of project organization?
Make sure your run this command from the project.json that has your EF Commands and your DBContext. You will not be able to run this from the artifacts folder since dnx custom commands like ef are registered on a per project.json basis.
If you are not already on the latest beta, it would be a good opportunity to try it again on beta8 to make sure everything works.
PS: Not just dnvm upgrade but the tooling as well.
If nothing works, checkout this other question. You will need a Startup.cs but it doesn't need to run anything in particular. It just need able to configure the dependencies.
We have a situation. Our company has Framework build on .net which is used by products developed using that Framework. Now this Framework is using EF code first. We want to implement EF Code Migration though generated migrations definitions because our entities are there in one of the Framework project. So I have implemented it. But the situation is this Framework we are distributing to other products as Nuget package (internal).
Now the situation is lets say ProductA is consuming the package which has xyz.dll which has migrations enabled in it. Now the developers of "ProductA" wants to upgrade the database created by Framework EF code first using that xyz.dll migrations, but this dll is only added as referenced dll. So running command in package manager console like Update-Database is not working because project is not in the current solution and its in reference dll
How do I solve this?
This is actually pretty easy to solve, the project which you add your nuget package to also needs to reference EF.
You can actually enforce this inside your nuget packages with a dependency eg:
<dependencies>
<dependency id="EntityFramework" version="4.2.0.0" />
</dependencies>
in your nuspec (obviously update the version with the one you are using)
See: http://docs.nuget.org/docs/reference/nuspec-reference#Specifying_Dependencies
and
http://docs.nuget.org/docs/reference/versioning#Specifying_Version_Ranges_in_.nuspec_Files
for some more details around how the dependancy syntax works
Using the Nuget package I downloaded and used Entity framework. I created a class library use the Entity framework and another windows forms application that uses the library to create data.
While deploying to production, I used with Windows Forms Application bin content but EntityFramework.dll is not part of it.
My question is :
How to deploy/install the Entity framework into production without using Visual studio/Nuget package?
Appreciate your responses.
If you set the Entity Framwork reference to Copy Local = True, it should deploy into your bin folder when you build the project