I want to share the transition rake from EFW 5 to 6 in the case of DataBase-First.
I work closely with the Entity Framework from the cradle. Moved to him with Linq2SQL.
I didn’t see any problems with transitions between versions. And in general - each transition met expectations.
But today I was a little disappointed.
At the start, I have 6 pieces of DataBase-First repositories scattered on the VS 2012 solution on .NET 4.5. And I tried to translate them into EFW 6.
So, what to do and in what order.
')
1. Go to the NuGet Manager (Manage NuGet Packages), open the Updates tab and install the Entity Framework 6 (6.0.1)
This procedure will remove references to old assemblies and add two new assemblies to the project (EntityFramework.dll, EntityFramework.SqlServer.dll)
This must be done for every project where there is an EFW. If all this eventually runs somewhere in another application - then there you need to make similar changes in app.config (web.config)
2. You will have a lot of compilation errors in your project. But do not rush to fix them. First, we replace the entity generator and, thereby, automatically correct some of the errors. If the project already used generators - delete (search and delete * .tt)
Go to the chart view, press the right pedal and select "Add Code Generation Item" and select "EF 6.x DBContextGenerator".
If you have VS 2012 (and not 2013) installed, then you must first install
Entity Framework Tools 63. Now we correct compilation errors.
As a rule, errors are related to the fact that the namespace has changed.
In most cases, the change template is this: after System.Data, an .Entity.Core is added.
Everything, the project is ready to start.
And now about the rake.
1. Lost (transferred) a bunch of methods that are not fixed in the code automatically.
For example:
Context.DeleteObject () is no longer there, now go to the desired DbSet and call Remove () there.
context.Delete(user);
Context.AddTo *** is also gone now, go to the desired DbSet and call Add () there.
context.AddToUsers(user);
The DbSet.AddObject method is also gone, but here you can decide to use the AutoCorrect [AddObject] => [Add]
Particularly advanced can write Extension.
2. Internal types have changed.
If earlier context.Connection was of type EntityConnection
But now SqlConnection suddenly appeared there.
What broke a part of my code (the meaning of the code was to find the connection string in “narrow” places and do the necessary things on ADO.Net)
3. In general, the events disappeared from the context.
Those. now there is simply no event context.SavingChanges.
4. Classes that are generated now do not have the former functionality. I would say that they now do not differ from structures at all.
They are not even inherited from EntityObject.
UPDAuthors do not plan to support or develop Self-Tracking entities.
Proof5. There were two repositories based on different databases. They had tables with the same name. As a result, the repositories had classes with the same name, but different namespaces. On Entity Framework 5, this was not a problem. But on 6-ke the code was compiled, but at runtime I caught an exception, something about the impossibility of resolving a name (these same classes from different namespaces appeared in the message)
Items 3 and 4 suggest that the DataBase-First approach was merged. All that remains is Code-First + a screen in the form of a class diagram browser.
Well, fatalities - after switching to 6.0.1, my code began to work slower.
Perhaps the fact is that other, more optimal queries were generated and they went past the indices created for EFW 5.
But I did not begin to understand the reasons. Just postponed the transition to more free time.