EF 4.3.1 with VS 2011 - entity-framework

I need to know if it is possible to start using the latest version of EF (4.3.1) with VS 2011 without having to install these CTP components as stated here.
I had these components installed but I removed them and since then I can't add a new edmx file to .net 4 targeted project; it complains about missing reference to System.Data.Entity.
Do I need to re install VS 2011?

After I removed and reinstalled Visual Studio, I still couldn't get red of the error, so I used process monitor to log what Visual Studio is doing with System.Data.Entity as a path filter, turned out that Visual Studio was reading from
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\policy.4.0.system.data.entity v4.0_0.0.0.0__b77a5c561934e089\policy.4.0.system.data.entity.config
which had binding to the
System.Data.Entity.dll v 4.2.0.0
once I cleared the file VS was worked like charm.
The CTP uninstall left this out.

Yeah should work with no issues using .net 4, however theres a list of known issues when using .net 4.5. You dont need to re-install vs to get version 4.3.1 of entity framework, simply install it from the nuget package gallery and if you are using .net 4 it all seems to just work.
Issues listed when installing EF4.3.1 on .net 4.5 include those listed below.
Known Issues with Entity Framework 4.x and .NET Framework 4.5
Entity Framework 4.1 thru 4.3 included additional data annotations in the
System.ComponentModel.DataAnnotations namespace in the EntityFramework assembly.
In .NET 4.5 these annotations were moved to be part of the .NET Framework in the
System.ComponentModel.DataAnnotations.Schema namespace of the
System.ComponentModel.DataAnnotations.dll assembly. If you are using EF 4.x and targeting
.NET 4.5 this results in two data annotations with the same name in different assemblies.
Because the annotations in the .NET Framework are in a different namespace we were not
able to use type forwarding to avoid this conflict.
It is possible to use EF 4.x on .NET 4.5 but we recommend using the latest pre-release
version of EF 5. If you are not using the affected data annotations there is no impact
on your code. If you are using the data annotations in a C# project you can use the extern
modifier to ensure your code uses the annotations from EntityFramework.dll
(http://msdn.microsoft.com/en-us/library/e59b22c5(v=VS.80).aspx). If you use the new
annotations from the System.ComponentModel.DataAnnotations.dll assembly in .NET 4.5
they will not be processed by Code First.
The affected annotations are:
Column
ComplexType
DatabaseGenerated
DatabaseGeneratedOption
ForeignKey
InverseProperty
MaxLength
MinLength
NotMapped
Table

Related

Set .NET Framework version for ScriptComponentProject

Is it possible to set the .NET Framework version for a ScriptComponentProject?
Currently it defaults to .NET 4, but I want it to be .NET 4.6.1
I've looked on the documentation page for ScriptComponentProject (https://www.varigence.com/Documentation/Samples/Biml/Script+Component+Project), but without any luck.
Ah, I found the answer! You need to set the Target Framework Version in your script project:
https://www.varigence.com/Documentation/Language/Element/AstComponentScriptProjectNode
And I think the available values are these:
Unspecified
Unspecified .NET Framework Version
NetFX20
.NET Framework 2.0
NetFX30
.NET Framework 3.0
NetFX35
.NET Framework 3.5
NetFX40
.NET Framework 4.0
NetFX45
.NET Framework 4.5
NetFX451
.NET Framework 4.5.1
NetFX452
.NET Framework 4.5.2
NetFX46
.NET Framework 4.6
NetFX461
.NET Framework 4.6.1
Which can be found here: https://www.varigence.com/Documentation/Api/Enum/ScriptProjectTargetFrameworkVersion
If you are using BIMLExpress 5.0.6xxx, you have probably faced the same issue.
I opened the generated .dtsx package and found that the TargetFrameworkVersion node placed inside of a separate PropertyGroup node. After I had moved it out to the first PropertyGroup of the same arrayElement node, then reopened my package in Visual Studio again, issue was gone! So you can write a script to move TargetFrameworkVersion node into the proper place for now.
Varigence support team told me that a public preview release is coming late next week which will include a fix for that (+also VS2017 support!).

Can I use EF4 in VS 2012?

I wanted to follow up on a post from last year ("EF5 , Widows Forms , Dragging a chield entity from project datasource into a GridView creates only 2 columns").
I believe the problem described with EF5 is still true and the solution found (use EF4) continues to be the only reasonable answer.
Before I upgrade to VS2012, I wanted to check whether anyone knows if there is any problem using EF4 in VS 2012.
Anyone with experience on this?
VS2012 requires .NET Framework 4.5 which is an in-place update. This means that once you install the .NET Framework 4.5 it will be always used when running .NET Framework 4 or .NET Framework 4.5 apps. This also means that you will be running EF5 even if you target .NET Framework 4 in VS (targeting is only a design time thing which prevents from using APIs that were not available in the targeted .NET Framework version while at runtime the app will use the version installed on the box).
With regards to the problem you are reporting - take a look at this bug report on the EF codeplex site as it apparently contains a solution to the problem

Enum in Entity Framework - how to create it

I watched the video here: http://msdn.microsoft.com/en-US/data/jj248772, but I can't see the option to create an enum out of a property in the context menu. Also, I can't add one in the Model Browser. I have Visual studio 2012 and EF5, EntityFramework Assembly version 4.4.0.0
Entity framework assembly version should be 5.0. You are most probably targeting .NET 4.0. You need .NET 4.5 to have enum support (you will need to uninstall EF package and install it again to get EF 5.0 once you change target .NET version).
Edit: EF 6.0 should provide enums for .NET 4.0 as well.

Upgrading from the June CTP EF 4.2

We're currently developing an application that is using EF Code first (EF June 2011 CTP).
My first question is: Is it worth trying to upgrade to use a later version of EF?
Secondly, if so, does anyone know the steps involved to upgrade - when I try to install the NuGet package for EF 5.0 - beta 2, I end up with issues as the target framework is still 4.2.
Many thanks,
James.
The CTP is long time dead with no other version coming because all that stuff is currently part of .NET 4.5 beta and EF 5.0 beta. You must upgrade to those two and the upgrade will consist of re-targeting application back to .NET 4.0 / .NET 4.5, removing all dependencies to your current EF version and re-adding those dependencies for .NET 4.5 / EF 5.0.
Some time ago I wrote a blog post on this: http://blog.3d-logic.com/2012/04/11/entity-framework-zombie-a-k-a-microsoft-entity-framework-june-2011-ctp/. There is a number of issues with CTP 4.2 because of technical challenges related to shipping a .NET Framework library out of the .NET Framework (like 4.2 target). Move to .NET Framework 4.5 that contains the same feature set as EF 4.2 + bug fixes and has a go-live license. Use EF 5.0 on top of it and you will be in a better world.
Thanks for all the responses.
My main issue is that we rely heavily on ENUMs in our implementation of 4.2 code first. I attempted to migrate the project to 4.5 but ENUMs are not supported, and there is also an issue with table per hierarchy (which is easy to fix). The next move will be to upgrade to VS11 and use 5.0 - but this is a big undertaking.
#jwsadler:
Enums are supported by core EF libraries released as part of .net Framework 4.5 (e.g. System.Data.Entity.dll). To make enums work with CodeFirst/DbContext you do need EF 5.0.0 package from NuGet (use Install-Package EntityFramework -pre (-pre is important)). You need VS 11 for this since Visual Studio 2010 cannot be used to create applications that target .NET Framework 4.5. Note that when installing the nuget package on Visual Studio 11 the target version of the .NET Framework set for the project is taken into account. If you target .NET Framework 4 you will not be able to use EF5 features like enums or spatial.

EF 5.0 Enums Not Generating

BACKGROUND
I'm using VS 2010 on a machine where I installed .Net 4.5 which I've read was an in-place install (overrode the .net 4.0 version).
I have projects still targeting 4.0 and 4.5 option is not available but was told it's ok since 4.5 was an in-place install. I then installed EntityFramework -pre via nuget and notices when I ran Upgrade-Database -Script commands, it would not generate enum properties.
I then found this. I tried doing everything from scratch again but it was still adding EntityFramework 4.4 instead of 5.0. So I manually changed all references to point to the 5.0 version to make sure I have EF 5.0 version. All compiled.
PROBLEM
When I run
Enable-Migrations -EnableAutomaticMigrations
I get "No classes deriving from DbContext found in the current project.
Edit the generated Configuration class to specify the context to enable migrations for."
So I manually made sure that my class is correct as in:
internal sealed class Configuration : DbMigrationsConfiguration<DataContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
DataContext subclasses DbContext.
When I run
Update-Database -Script
I get "No migrations configuration type was found in the assembly 'MyProject'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration)."
MyProject does have the configuration class I mentioned above and in Package Manager Console I am choosign the right dropdown for my project containing Migrations folder and this Configuration class.
QUESTION
What do I do to make sure when I install EnittyFramework via nuget that it adds the 5.0 version and not 4.4 even though I have .Net 4.5 installed?
If I can't do anything related to the question above, what can I do to make sure Upgrade-Database spit out a script?
Entity Framework 5.0 isn't out yet. There are prereleases, but you need to specifically enable prereleases in order for NuGet to display them.
However, keep in mind that EF 5.0 won't support everything in .NET 4.0 that it will in .NET 4.5. Yes, .NET 4.5 overwrites .NET 4.0, but if your project is in VS2010, it will be configured to build for .NET 4.0, not .NET 4.5. It cannot assume .NET 4.5 features, because the result needs to run on systems that don't have .NET 4.5. You're targeting .NET 4.0, after all, and enum support isn't in the EntityFramework DLL you get from NuGet, it's in the System.Data.Entity DLL that's part of the .NET runtime, so it cannot be added in .NET 4.0. You can install the Visual Studio Beta to create applications that target .NET 4.5.
In short: "was told it's ok since 4.5 was an in-place install" -- no, it's not ok for your purposes.