C
C#BlueJayBird

✅ Is it possible to disable these properties on EF6? Web API 2 project, multi-layered, NF472

SCENARIO - Solution type is NET Framework 4.7.2 (it is, what it is). - I have this project, I'm consuming theses objects from the DB through EF (data layer), see image 5 . Information goes through to other layers before reaching out to the web API layer, - Web API works (image 1), I can make a request and get data back as seen in Postman (image 2) and browser (image 3). - I was getting this error https://stackoverflow.com/q/19467673/7389293 which I solved by just using a rough DTO to pass what I get from EF, I'm planning on using AutoMapper down the road. QUESTION - Is there a way to not generate those public virtual fields on the EF classes? So I can throw the object from the EF right away into the API response.
Stack Overflow
Entity framework self referencing loop detected
I have a strange error. I'm experimenting with a .NET 4.5 Web API, Entity Framework and MS SQL Server. I've already created the database and set up the correct primary and foreign keys and relation...
C
Cisien512d ago
If you dont make them virtual, you dont get lazy loading, which just means you need .include Its best practice to use separate models for your api anyway
B
BlueJayBird512d ago
So, you're saying that AutoMapper is the way to go, and getting rid of the virtual part is bad idea. Right?
C
Cisien512d ago
Not automapper specifically, but split models from your db and your api. Disabling lazy loading is your choice. There are pitfalls to using lazy loading, such as slower queries because they pull back excessive data, but code is much cleaner Cleaner in that each query doesnt need a mess of includes For comparison, lazy loading is disabled by default in core
A
Angius512d ago
.Select() And remove virtuals preferably
B
BlueJayBird512d ago
Ok, I've read your comments, guys. I'll try to fix this next week. See you then.
C
Cisien512d ago
if you remove virtuals, you may go a step further and disable lazy loading explictly
A
Accord511d ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
B
BlueJayBird508d ago
I solved this by changing the following configuration in the EF context: _context.Configuration.ProxyCreationEnabled = proxyCreationEnabled; This seems to have disabled the use of virtual fields in the entities I was retrieving from the DB using EF.
Want results from more Discord servers?
Add your server
More Posts
✅ This EntityFramework query can not be translated for SQLiteThe issue lies within `Intersect`. The point of the query is to fetch the current user, and to popul✅ Detect Network RequestI want make service that detect all connection to specific domain or ip? And if this request contain❔ CORS errorHello, I have Cors error on my project. I add Addpolicy in my configureServices and also add app.Us❔ Ambiguities? How?Idk how i can resolve this i don't see the problem✅ How can I get rid of this annoying pointer thing in the first row, datagridview winforms^✅ How can I use a row header of a datagridview to display the row number instead of being empty?^✅ How can i properly display this datagridviewHow can i get rid of the row select thing on the left (just white space)✅ I am trying to output a 2D array to a datagridview, but it is not outputting correctlyIt is saying System.Int32[]✅ Task not returning and stopping programHey, I am currently trying to start one task for every string in the list, but this isn't working an❔ DbContextCan i use this in a non-asp area like for example, a simple program to make few tables using DbSet✅ The specified deps.json does not exist while scaffolding DBI am going through a tutorial to create a Web API app with ASP.NET6 and MySql. I wanted to scaffold ❔ C sharp object reference errorI am trying to reference an object that I'm displaying on PageHeader.xaml and I keep getting this erInteroperability issues (PInvoke)Hi! I'm calling a native CPP library and retrieving a struct by reference which returns a struct con❔ SKIA SHARP PROBLEMError: ```cmd Dec 02 16:05:22 mourashop shopmoura-api-app[3847595]: Unhandled exception. System.Argu❔ FluentAssertions excluding collection elementsI have two IEnumerable<Claim> tmp1, tmp2 and I want to see if they are equal, except for the claims ✅ Best way to display a 2D arrayWhat would be the best way to display a 2D array in winforms c#, with the best design, or is just prWrong count for my inversions functionIt is supposed to be 10 inversion count but I am getting 13 ```csharp var array = new int✅ Need some help with classesNot too sure how to correctly use attributes from a class in a class function✅ Type CastingHi, Just wondering how I would type cast the object 'control' to the type 'telerikslider'?❔ Mocking with EntityFrameworkCoreHm, I'm creating unit tests for a class that has a `private readonly MyDbContext dbContext;` that ca