Entity Framework 6.4.4 (.NET 4.7.2) - No connection string named - entity-framework

Good day,
I've created a C# .NET 4.7.2 class library project which integrates EF6. When the parent project makes any call to the DLL for db access, the above exception is thrown.
A common solution is to include a reference to EF in the parent project and to copy the connection string element from the class library's app config file. This indeed works, but is not ideal. I really envision all of these settings encapsulated within the DLL.
Anyone have a work-around?
Thanks.

Related

Reference .net core 2.0 into a .net 45/46 project

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

Installing EF to .NET core library project

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.

Can't add Entity Framework migrations when project is split

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.

Why is AutomaticMigrationsDisabledException thrown?

We have
An Old Web Project
A New Web Project
A Class Library containing all Entity Framework code
All three projects reference Entity Framework 6.1.3.
The Class Library is shared by Old Web Project and New Web Project. Both web projects have a file reference to Class Library. They both point to the same location on disk.
Both web projects are configured to use the same database.
When I run Old Web Project in Visual Studio, it runs just fine.
When I try to run New Web Project in Visual Studio, it throws an AutomaticMigrationsDisabledException.
When I temporarily add ClassLibrary.csproj to the New Web Project's solution and run
Add-Migration TestMigration -ConfigurationTypeName MyConfiguration -ProjectName ClassLibrary -StartupProjectName NewWebProject -ConnectionStringName MyContext
it scaffolds a migration with empty Up() and Down() methods, indicating it did not find changes after all.
What might cause New Web Project to throw an AutomaticMigrationsDisabledException under these circumstances? How can I further diagnose the issue?
I had very carefully checked that New Web Project's file reference to ClassLibrary.dll is the correct one and that the DLL in question is up-to-date.
As a test, I added a new method to a class in ClassLibrary.dll, and found that New Web Project could not resolve it.
I deleted the existing file reference and added it back in, and the problem resolved.
For an unknown reason, an older copy of ClassLibrary.dll was being referenced in contrast to the information seen in the Properties window for that reference.

Deploying Entity Framework 5 in production without using Nuget

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