Toggling ProxyCreation in EF7 under new configuration - entity-framework

So in EF6, one could disable proxy creation like so:
this.Configuration.ProxyCreationEnabled = false;
From what I could find, the configuration scheme under EF7 has changed, but I cannot find anything on how to do so. I went through https://docs.efproject.net/en/latest/miscellaneous/configuring-dbcontext.html and even analyzed the DbContextOptionsBuilder object, but cannot find anything on it.
Am I going about ti the wrong way or is there something im missing? Thanks in advance.

EF7 EF Core 1.0 does not do proxy creation, so accordingly, there is no configuration option for this. See https://github.com/aspnet/EntityFramework/issues/997

Entity Framework Core 2.1 starts to support Lazy load. Please see: https://learn.microsoft.com/en-us/ef/core/querying/related-data#lazy-loading
Here is recent question with answers from stackoverflow:
What is the equivalent of .Configuration.ProxyCreationEnabled in EF Core?

Related

Trying to upgrade, from EF4.1 to EF6.1, ObjectContext reference code?

I am trying to upgrade my MVC3/.NET4.5 application to use EF6.1, in the main part for its performance improvements.
One of my problem code lines is :
private AppEntities db = new AppEntities();
I have removed system.data.entity from references and web.config, but this line still seems to be looking for this dll. I did try and add:
using System.Data.Entity.Core.Objects.ObjectContext;
Did not seem to fix the issue with AppEntities line trying to find system.data.Entity v4.0.0.0
Many thanks
EDIT:
I managed to sort this by adding:
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
to AppEntities.cs file.
Also needed to add to some of the POCO files.
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
It all builds fine.
However my problem now is that it seems to take an age to show the page on first load, guess this is to do with native code creation. Also I have heard that much EF code that was native in .NET is now MSIL in Entity Framework.dll and thus need compiling to native code as well. Perhaps this is what is causing my pain, see: EF6 Warm up metrics

BreezeJS: Metadata() Error after upgrading Breeze 1.2 to 1.4 and EF 5.0 to 6.1

I tried to upgrade my project in Angular using Breeze 1.2, EF 5.0 to use latest Breeze/EF. The project was working fine, but I ran into various issues after upgrade.
Actually, I only need some new features in EF, so I tried to upgrade EF from 5.0 to 6.1 first. However, I can't install EF 6.1 with Breeze 1.2. So, I had to upgrade to Breeze 1.4 first. After that, I had to make some changes due to new namespaces to get the project compile again.
First problem is that route has changed. In v1.2, I used to call
var manager = new breeze.EntityManager("api/breeze");
but in v1.4, I had to call
var manager = new breeze.EntityManager("breeze/breeze");
Then, I got this error on client:
GET http://localhost:1476/breeze/breeze/Metadata 500 (Internal Server Error)
On server, I got this error message on call to get Metadata():
The property 'Id' cannot be configured as a navigation property. The
property must be a valid entity type and the property should have a
non-abstract getter and setter. For collection properties the type
must implement ICollection where T is a valid entity type.
I'm getting lost here. I found this post and this post mentioning the namespace changes. However, I have no idea how to fix it in my case. For example, on server, my EntityState is coming from Breeze.ContextProvider, not from System.Data.
What is problem? Are my entities (I have a lot!) no more valid? Do I have to redefine all my entities?
Any hint is much appreciated!
Okay, after much struggle, I got it work now, but with the same code, so I'm not sure how it got fixed. This are the steps I tried. I commented out all the entities first, then I get the metadata without problem. Then, I added back the entities one by one and run get metadata, but no more errors.
One possible guess is that, after upgrading to EF 6.1, I didn't change the entities, so the my db schema didn't change and EF 6.1 is incompatible with the previous schema. Once I changed the entity, the auto migration kicks in. It's just my guess.
Hope it helps in case somebody runs into the same problem.

Caching with Entity Framework

has anyone some experience with caching and EF ?
I was looking at the EFProviderWrappers http://code.msdn.microsoft.com/EFProviderWrappers but this project seems to be outdated. Does someone used it with success ?
Or are there other better solution ?
If you want to cache LINQ query results I recommend you try the Pete Montgomery solution. It is applicable in ASP.NET but can be used in desktop apllication if replace HttpRuntime.Cache to System.Runtime.Caching.MemoryCache.Default.
You may try to look at second level caching made by Eye Soft. Here's link to Nuget package and its source code on Codeplex. It's based on EFProviderWrappers, but refactored and seems up to date more or less.

How to disable code-first feature in EF (MVC4 Visual Studio 2012)

How to disable code-first feature in EF (Visual Studio 2012)
I am using Visual Studio 2012, MVC4 (Internet application template).
I want to use EF, but not with its code-first feature. I would want the application to error out, rather than create or modify my database based on my code. (i just can not live with this feeling of my database being changed behind the scenes ... i want the application to use the exact db i have created ... and if there is any thing that has to be changed, i'll do it my self)
is this possible with the new Ef (VS2012)?
i have seen many people asking this, but so far i am unable to find the answer.
You can use Code First and ensure that your database never gets updated or overwritten when you change your model by setting the database initializer to null:
Database.SetInitializer<MyDbContext>(null);
It's a static method of the Database class and should be called at the beginning of your application, for example in global.asax or in a static constructor of your context class. Doing this you have to change model class and database schema manually so that they match.
You can also use the Reverse Engineer feature to create a Code First model from an existing database. It is explained here: http://msdn.microsoft.com/en-us/data/jj200620
Or if you don't want to use Code First at all and work with a model designer you can use the Database First approach, explained here: http://msdn.microsoft.com/en-us/data/jj206878
An overview about all the possible options is here: http://msdn.microsoft.com/en-us/data/ee712907.aspx

Is it possible to disable/override a ScriptResourceMapping requirement?

I upgraded a WebForms project to .net 4.5, and received this error:
WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping
for 'jquery'. Please add a ScriptResourceMapping named
jquery(case-sensitive).
I'd like to enable UnobtrusiveValidation, but I'm using Combres for Javascript resources, so I don't want the ScriptManager to try to download it again. Is it possible to tell the ScriptManager to just trust me that it will be loaded? In other words, I want to add a mapping for "jquery" that does nothing. It's apparently not possible to add a ScriptResourceDefinition with a name but no paths. Is there any other way?
As far as I can tell the answer is no.
This question has been asked on http://connect.microsoft.com/VisualStudio/feedback/details/735928/in-asp-net-web-application-visual-basic-the-requiredfieldvalidator-doest-work and on http://forums.asp.net/t/1850831.aspx/1 with no answers.
As a quick and nasty workaround to this problem I have added an empty file called DummyJQuery.js into the solution put the code below into application_start:
Dim jQuery As New ScriptResourceDefinition()
jQuery.Path = "~/js/DummyJQuery.js"
jQuery.DebugPath = "~/js/DummyJQuery.js"
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery)
Answer described here: http://www.codeproject.com/Articles/465613/WebForms-UnobtrusiveValidationMode-requires-a