How do I update my Model without updating the EF version? - asp.net-mvc

I am working on a Legacy project which uses "EF4.0" (system.data.entity version 4.0.0.0 runtime version v4.0.30319.
There are many places in the project where properties on "context" objects are used which are not available in the newer version.
DB team has made some changes & added a few entities which I need to use in the project, now when I try to " Update Model From Database" VS asks me to select the version of EF I want to use and gives only 2 options "Entity Framework 5.0" & "Entity Framework 6.x". But I don't want to update to these versions, as this will require code changes in many places which I want to avoid.
This is a DLL project and in app.config there are only connection string settings, no assembly configuration sections.
The version of the visual studio I am using is VS 2017 community edition(version 15.3.3).
While googling i found some articles which suggested i installing 4.x runtime via NuGet package manager, but i couldn't find any package for version 4.0
(https://learn.microsoft.com/en-us/ef/ef6/modeling/designer/select-runtime-version)
How do I update my Model without updating the EF version?

Related

entity data model wizard crashes with oracle connection

When trying to create model with entity frameowrk database first method, the entity data model wizard crashes. I am trying to connect to oracle database.
Oracle.ManagedDataAccess version :19.6
Oracle.ManagedDataAccess.EntityFramework version : 19.6
ODAC Version 18.3
Entity Framework Version:6.0
Image has been attached for refernce. Process after process mentioned in the image is crashing.
The rule still applies today. ODT Version must match the version of oracle.manageddataaccess and oracle.manageddataacess.entityframework obtained by nuget. It is very tempting to update thru nuget to a later version, but ODT will than crash.
I often have a parallel project to generate my code first model and than copy the files to my model project.
I'm using:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Microsoft ASP.NET MVC 5, NET.Framework 4.6.1
It was happening the same error in my project, I was tryng to use EnityFramework and Oracle Manage Data Access most recent versions. When downgrade the fallowing versions. It start to working without any errors
Versions that worked for me:
EntityFramework 6.1.3
Oracle.ManagedDataAcces 12.2.20230118
Oracle.ManagedDataAcces.EntityFramework 12.2.20230118
The EntityFramework 6.4.4 worked to... But every time I try to scaffold a Entity from the database, It autommatically downgrade to version 6.1.3

Cannot connect to Oracle Database with Entity Framework in ASP.NET MVC project

Context : I'm creating a web app (in ASP.NET MVC 4) that will offer access to an already existing Oracle database. I'll only need to be able to read data from that DB, no insert, or update, etc. I'm working in Visual Studio Express 2015 for Web.
I've searched a lot for answers to my problems, but to no avail.
My goal is to create models with Entity Framework Database first. I have added Entity Framework, Oracle.ManagedDataAccess, and Oracle.ManagedDataAccess.EntityFramework to my project with NuGet.
However, when I try to add an "ADO.NET Entity Data Model" to my Models, whether I select "EF Designer from database" or "Code First from database", I get the following:
What am I missing ?
I've found resources saying I need to install Oracle Developer Tools for Visual Studio. However, it is not supported in Visual Studio Express, and I cannot change my IDE.
I don't have Oracle client installed on this dev computer, but I sqldeveloper, and have no issue accessing the database with it. Do I NEED to install the Oracle client ? Aren't the dll installed throught NuGet enough ? I'm asking because I'm an intern, and installing any new piece of software requires validation, that takes quite a long time.
add connection your database to your project
Insert New Item an Empty Dataset
In that dataset insert TableAdapter from toolbox into your dataset.
window pops up for selecting tables (you can write sql for select a desired table)
after step 4. you have your entity.
I have the same bug and I fix like this:
You need instal:
Microsoft Visual Studio 2015 or later with .NET Framework 4.5 or later.
Oracle Database 12c or later.
Oracle Data Access Components (ODAC) 12c Release 3 (12.1.0.2.1) or later from OTN. The ODAC download includes Oracle Developer Tools for Visual Studio and ODP.NET
Files required for this tutorial.
Using NuGet to Install and Configure Oracle Data Provider for .NET tutorial.(install: Oracle.ManagedDataAccess.EntityFramework from Nuget).
refer: http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/2015/entityframework_linq_modelfirst/Entity%20Framework%20LINQ%20and%20Model%20First.html#overview

Updating EF 4.6 edmx model in VS 2015

We have a legacy EF 4.6 project not yet migrated to a newer version of EF.
Now I want to update the model from the database (add a new table) so I open the EDMX in the designer like in VS 2010 and choose "Update from the database". This gives me a warning that "Your project references an older version of Entity Framework. ..."
The only choice in this update from the database action it gives me is EF 5.0 but I need EF 4.6
Is it possible somehow to make the model update in the designer without upgrading to a newer version of EF or using an older version of VS?
I have just come up against the same problem (although I was stuck on v4.0.0.0). The solution was to install ADO.NET Entity Framework 4.1.
This put the required tooling on my computer and allowed me to update my model.

MaxLength Attribute in EF4.3.1

The type 'System.ComponentModel.DataAnnotations.MaxLengthAttribute'
exists in both
[path...]\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll
and
'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework
\.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll'
Now, I have read on msdn that its safe to exclude the EntityFramework reference (which was added through the nuget package). However, when I do that, I cant create a DBContext properly as the DbModelBuilder class lives in the EntityFramework dll. Also, some other critical classes are missing when I remove the EntityFramework refference so this is old and irrelevant solution now.
Update (disambiguation): Both System.ComponentModel.DataAnnotations.dll and EntityFramework.dll include System.ComponentModel.DataAnnotations.MaxLengthAttribute. The problem is that each dll also includes other classes that are critical to EF code-first design. For example:
EntityFramework.dll:
- System.Data.Entity.DbModelBuilder
System.ComponentModel.DataAnnotations.dll:
- System.ComponentModel.DataAnnotations.RegularExpressionAttribute
Add this statement to top of your class
using System.ComponentModel.DataAnnotations;
System.ComponentModel.DataAnnotations namespace is distibuted across the EntityFramework.dll and System.ComponontModel.DataAnnotations.dll. So you need to add a reference to both of that in your project to make use of DataAnnotations.
The MaxLenth attribute is present in EntityFramework.dll. So make sure you have that reference to that dll present in your project references section.
EDIT : As of .NET framework 4.5, this namespace is moved to the System.ComponentModel.DataAnnotations.dll. So If you use .NET Framework 4.5 with Entity Framework 4.3.1 or less, You will run in to this conflict. The solution is to switch to Entity framework 1.50 beta 1/ 2 release if you want to stick with .NET 4.5 or downgrade to .NET 4 to use EntityFramework 4.3.1.
From the msdn documentations.
Starting with Entity Framework 5.0 Beta 1, the EntityFramework.dll
does not contain definitions for data annotations. These definitions
were moved to System.ComponentModel.DataAnnotations.dll and are
defined in the System.ComponentModel.DataAnnotations.Schema namespace.
I didn't have the option of upgrading the project to use EF5, or downgrading the build machine to .Net Framework 4.
There is a way to solve this though! It turns out when you install Visual Studio 2012 it adds the following folder (amongst others).
C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0
In VS if you open a project targetting 4.0 and look at the properties of your reference to System.ComponentModel.DataAnnotations you'll see that the path is pointing to the above location, rather than the GAC.
This folder contains the original Framework 4.0 assemblies. If they're present on the machine then MSBuild etc., upon building a project targeting 4.0 will reference these rather than the modified ones that 4.5 puts into the GAC.
In our case this meant we could fix the problem by copying that folder from a dev machine with VS installed up to our build server in the same location. (N.b. We only needed to copy this folder, there was no need to install VS on the build server).
More info here: http://marcgravell.blogspot.co.uk/2012/09/iterator-blocks-missing-methods-and-net.html
Hope this helps someone else!

What are required assemblies for Entity Framework 4.1 and SQL Compact?

Previously I used Entity Framework 4.0 CTP5 (code-first) and SQL Compact in my projects. I had the following packages installed using NuGet:
SQLCE.4.0.8435.1 (version 4.0.8435.1)
EFCodeFirst 0.8 (version 4.0.30319.0)
EFCodeFirst.SqlServerCompact.0.8 (version 4.0.8435.1)
Now when EF 4.1 RC is published, I want to update all my libraries to the latest version. NuGet feed doesn't contain any updates for SQLCE.4.0.8435.1 anymore, but it has a new package 'SqlServerCompact - 4.0.8482.1' (new package, not a new version of existing package). Presume, that it was just renamed and I should install it. Is it right? Presume, yes.
NuGet also doesn't contain any updates for 'EFCodeFirst' and 'EFCodeFirst.SqlServerCompact' packages. But it has a new 'EntityFramework 4.1.10311.0' package.
So what should I install? Are 'EntityFramework 4.1.10311.0' and 'SqlServerCompact - 4.0.8482.1' enough for using EF code first with SQL Compact?
Yes, we're working on an EntityFramework and EntityFramework.SqlServerCompact this week.
I think we have to wait for them to release an updated EF + SQL CE library /sign

Resources