I have a project that uses Entity Framework 4.0. From within that project, I installed 4.3. Some changes appeared in my app.config indicating that I was now using 4.3. However, my generated code still inherits from ObjectContext and creates ObjectSets even if I delete and re-add the edmx. How do I get the generator to use DbContext and DbSets?
You must download DbContext T4 template from Visual studio gallery - you can get it from extension manager in Visual studio.
Related
I have a problem with creating migration for Entity Framework 6 in code first approach. I already created migration, but later when I tried to create new, this was the errror:
Your target project 'Blog' doesn't reference EntityFramework. This
package is required for the Entity Framework Core Tools to work.
Ensure your target project is correct, install the package, and try
again.
I checked NuGet, EF6 is installed, alongside with these packages
When trying to add a migration add-migration "Inicial" -Verbose , this error message appears:
No migrations configuration type was found in the assembly 'DevIO.UI.Site'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
I followed the message instruction and typed the command Enable-Migrations, but there was still an error
No context type was found in the assembly 'DevIO.UI.Site'
What can I do?
Assuming you already have a DbContext class in your solution, you need to know which project it is in. You should be adding migrations in that project. If you're using the Visual Studio package manager console for this, you will need to set the Default Project to the project which contains the DbContext (i.e. in the dropdown at the top of package manager console).
Entity Framework is different from Entity Framework Core. You are using Entity Framework (which we know because EF Core doesn't include an Enable-Migrations command), but your DbContext is coming from the Microsoft.EntityFrameworkCore namespace. If you replace using Microsoft.EntityFrameworkCore with using System.Data.Entity that should be the correct DbContext class for Entity Framework.
I figured that if you install a NuGet packages named Microsoft.EntityFrameworkCore.Tools it will solve this problem .
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
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
I see examples about code-only POCO for en entity framework 4, but I cannot find the classes EntityConfiguration and ContextBuilder and I cannot see which reference I need to add to have them.
Is it part of the .Net Framework 4 or do we have to download something else?
The POCO stuff you're looking for is in a separate download. Current version is at http://www.microsoft.com/downloads/details.aspx?FamilyID=af18e652-9ea7-478b-8b41-8424b94e3f58&displayLang=en
Once you run the installer, you'll need to grab the Microsoft.Data.Entity.CTP.dll file (mine was in the C:\Program Files\Microsoft ADO.NET Entity Framework Feature CTP3\Binaries directory). Make a project reference to the new dll and you should be set!