Entity Framework Pre-Generated View on Assembly - entity-framework

I just started using EF 6 and I noticed that the first execution takes more time because it needs to be compiled, so I researched and found that you can pre-generate the view.
I used EF Power Tool to generate the view: http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/
It's a dll, and I'm building using the option Embed in Output Assembly.
The problem is that even though I have the view.cs when I execute the first query I have the same delay, so it seems that my library is not using the pre-generated view.
What could be wrong? I'm passing the connection to the entity using an EntityConnectionStringBuilder returning a EntityConnection object.
Also I tried changing the view.cs to Embedded Resource, since with Compile I did not have any changes, in both ways I still have the first time delay.
I'm sure I'm missing something, but not sure what.
Thanks in advance,
Lucas.

EF5 views will not work with EF6 (in addition to that there are some issues with EF6 Beta 1 and EF6 RC1 which prevent using views with EF6 - these issues should be fixed for EF6 RTM). I created a T4 template for generating views for EF6 - you can find more details here - again due to the problems above the views generated by the template will not work for EF6 RC1. If you absolutely think you need it you can try the version from my github - it was updated to work with EF6 RTM and also works with nightly builds.
Anyways, I am pretty sure that this is actually not view generation that are causing the issues (actually the performance of view generation in EF6 has been greatly improved). We recently found a few performance issues (see 1674 and 1662) that are affecting start up time and we are looking at these.
EDIT
The version of the template that works with EF6 RTM (6.0.0.0, 6.0.1.0) has been published to the VS Gallery

Related

What is the best way to collapse all existing Entity Framework migrations

The project I am working on is using Entity Framework 4.3 and data migrations to keep the schema up to date. Over the course of the project the migrations folder has grown and now has over 600 files. This is huge. We now have a binary which is over 12MB due to all the migration meta data.
I would like to collapse all these in to one migration and start again. My concerns are:
Is this possible or will it cause problems with the migration history if I remove migrations?
Are there any guides around describing how to do this?
First: I recommend that you keep your migrations in a separate assembly so they don't have to be published with the application. It could be a simple console app that applies the migrations or a winforms GUI that generates scripts. But there's no reason for it to be deployed with the app imo.
Second: Understanding that you'd be giving up the ability to roll back to previous versions, you could just exclude-from-project all of your prior migrations then generate a new one which should then be able to create a database reflecting your current model. That would serve as your new starting point. Remember that EF doesn't always generate code to do everything you want in a migration, so you might have some hand-written migration code in other migrations you'd need to pull in.
Not sure past versions, but if you are here looking for the same solution for EF Core. You should be able to just delete the ModelSnapshot and re-run your migration to create a clean sheet.

Using Entity Framework 6 with EntityKey

I am trying to upgrade a big data project from EF 5 to EF 6. But when I run the code generation in EF6 tool the references to the related tables are no longer there.
So the following line of code no longer works.
dbTradeAllocation.ChargeTypeReference.EntityKey = new EntityKey("ICEEntities.SystemData", "ID", TradeAllocation.ChargeType);
Does anyone know if EntityKeys are still supported in EF6 ?
Thanks Paul
EntityKey is supported in EF6. However you cannot run EF5 code generation in EF6 - it won't work since there were changes in namespaces. I touched a little bit on this in my blog post about changes to EF Tooling in VS2013 - you can find the blog post here. If you want to use EntityObject/ObjectContext entities in EF6 you need to use EntityObject generator for EF6 which you can get from VS Gallery (note it requires .NET Framework 4.5 on the dev box).

Entity Framework Powertools - Code First Generate Views On Build

Right now Power Tools Beta 4 provides generation of views with a right click. This is fine as far as it goes but can cause issues because you have to remember to do it.
Is there any way that I can make it do the generation of views at compile time? (i.e. some sort of pre-build action or something?
Thanks!
You can use T4 templates for generating views I created a while ago. Take a look here for the EF5 version and here for the EF6 version. You will need to do some MSBuild work to make the T4 template run on Build. You can take a look at comments for this blog post where this is discussed a little bit.
EDIT
I also recently published Interactive Views for EF6 on NuGet so now you can have pre-generated views without having to generate them at the build time.

Data sources toolbox for VS2012 does not display my entity model

After adding an entity model either from the datasources toolbox itself or by adding it => "add" => "new item" it does not show up in the datasources toolbox and therefor i dont get that easy drop and drag functionality.
If I add a dataset it works but that is an older technology (is it not?) everything in my current project are entity models and to change to datasets (which only works if I add xmlns:yourAlias="clr-namespace:WpfApplication3") would be .. I don't think best practice and a waste of time.
I have recreated this same process of adding a entity model in VS 2010 and it works 100%, where i have the ability to simply drop and drag from the dataSource toolbox
Maybe ill just wait for VS SP1 before working with it for client projects. :(
//Edit
If I add the ADO.net Entity model in VS2010 and then load the project in 2012 it loads fine in the dataSource toolbox. This is an answer but not an ideal work around.
While working on a project I recently faced the same problem. It took me about two days of extensive research but I think I've finally found it:
http://msdn.microsoft.com/en-us/data/jj556581
At least for me it solved the problem. Please let me know if it helped you..
Being addicted to L2S, I tried to get familiar with VS2012 and EF5. But I nearly lost my nerves trying to use the data sources toolbox.
Finally I found a solution:
using Object Data Source is now the recommended approach for using EF in databinding scenarios. See this article for more details - http://msdn.microsoft.com/en-us/data/jj574514. The article also includes a link to revert to the old code generation if that is what you desire.

Updated to EF 4.2. Then what?

Ok, so I installed EF 4.2 from NuGet. Just did Install-Package EntityFramework. That's all I've done.
Now what?
How do I know I'm using the new Framework and not the old one.
I have an existing project previously with EF 4.0. I'm also using precompiled views and custom text templates. Everything looks exactly the same after I did the update.
There will be no change in existing project. EFv4.2 contains code first mapping approach and DbContext API - neither of those affects existing EFv4.0 projection. It also contains few minor helpers like strongly typed Include but you must use them in your code. That is not something that will magically change existing code.