Questions tagged [entity-framework]
An ORM built by Microsoft and is available as part of .Net framework 3.5 and later.
385 questions
1vote
1answer
174views
Is there a better way to soft delete navigation properties in Entity Framework 6 when using Repository pattern?
public void ReassignLineItems(InvoiceUpdateDto invoiceUpdate) { Invoice invoiceInRepository = _unitOfWork.InvoiceRepository .FirstOrDefault(invoice => invoice.Id == invoiceUpdate.Id); ...
2votes
2answers
113views
Could concurrent user-triggered data fetches and inserts lead to deadlocks in a multi-user ASP.NET Core + MSSQL application?
I'm facing a tricky situation that might result from a not thoroughly thought-out design, and I'm hoping to understand whether a deadlock might be a realistic cause – and if so, how to prevent similar ...
1vote
3answers
149views
Are there non-inheritance-chain-mess ways to make modular libraries that rely on Entity Framework based on one DB context in the using project?
I am developing some modular libraries that contain common APIs, data, and functionality. One of the core assumptions to these libraries is you would use which you want to compose your project, but ...
0votes
1answer
210views
Why is it so common to use the dbContext directly in the controller in a WebApi application?
Actually, in a Web API application using Entity Core, it seems very common to inject the application context to the controllers, so the controllers use directly the dbContext to do its work. Something ...
0votes
1answer
298views
Is IRepository allowed to know about database entities?
I am trying to apply Robert Martin's Clean Architecture on my .NET project. In one of chapters about boundary, it talks about that database interface should reside in business logic component rather ...
1vote
3answers
669views
Creating Unit and Integration Tests with Database elements
This is something that I've heard a number of opinions and theories about, but I'm still torn on how to go forward. For context, this particular issue deals with the following technologies, in case ...
3votes
4answers
703views
In EF why should a DB contexts not persist?
Are the reasons for why Microsoft states that DB contexts should not be long lived because of measurable effects (memory leak, resource hog, increased probability of data corruption, ...) or is it ...
0votes
2answers
105views
EFCore In Memory repository Unit Test of Encrypted data
I have in project linq repository unit tests. [Fact] public async Task Get_FromTreeEntitiesUnsorted_RetunsOrderByDescending() { //Arrange _contextReadonly.Entity.Add(new ...
0votes
2answers
547views
Should entities always be simple and mapped?
I am told everywhere that entities are only to represent the data structure, then entities should be mapped to a model and then the model possibly to a DTO. The other way is similar, DTO -> model -&...
0votes
0answers
45views
Designing an optimization on throughput of EF.Core application
I am looking for feedback on a design problem I encountered when processing batches of db entries. The issue at hand is efficiency and throughput of an application. The application looks like this ...
0votes
2answers
292views
Domain Project and Identity Project circular dependency
I am currently working on implementing the Clean Architecture pattern using Entity Framework. However, I've encountered an issue related to the design of my Domain project. In this project, I need to ...
-1votes
3answers
2kviews
How to properly design database in accordance with DDD
My Domain layer contains below model: public class ApiResource { public bool Enabled { get; set; } = true; public string Name { get; set; } public string ClientId { get; set; } public ...
1vote
3answers
2kviews
Using Repository Pattern with .NET Entity Framework with a single Get method with optional parameters for each table include
We have a very messy data repository component, with dozens of methods to interface a DbContext (entire database) in Entity Framework. It was (and is) coded in a way that adds a new repo method for ...
1vote
2answers
202views
Designing Products with multiple variations
I have a Product entity: public class Product { public int Id { get; set; } public string? Name { get; set; } public string? Description { get; set; } [ForeignKey("Brand"...
1vote
1answer
2kviews
Mapping between Entity and ViewModel
I'm trying to make an application in ASP.NET MVC. I'm using AutoMapper for the conversion between entities and ViewModels. In most cases, this works fine, but when I need to add some additional data (...