Questions tagged [entity-framework]
An ORM built by Microsoft and is available as part of .Net framework 3.5 and later.
382
questions
0
votes
1
answer
91
views
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 ...
0
votes
1
answer
272
views
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 ...
1
vote
3
answers
192
views
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 ...
3
votes
4
answers
446
views
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 ...
0
votes
2
answers
89
views
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 ...
0
votes
2
answers
358
views
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 -&...
0
votes
0
answers
43
views
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 ...
0
votes
2
answers
236
views
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 ...
-1
votes
3
answers
2k
views
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 ...
1
vote
3
answers
1k
views
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 ...
1
vote
2
answers
151
views
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"...
1
vote
1
answer
2k
views
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 (...
0
votes
1
answer
2k
views
Doubt about DDD, entity core and backing field
I was reading the documentation about how to use Entity Core in a DDD way. This is the documentation.
It is said that I can configure EF to can map an internal private field to a private field, the ...
-1
votes
1
answer
639
views
REST API designing resources for complex entities
I have an ASP.Net Core Web API where I am having difficulties designing the REST resources based on the EF Entities I have.
There are three entities that describe a Reservation. First, there is the ...
2
votes
2
answers
1k
views
Why should I use an ORM like Entity Framework Core?
I have taken over the maintenance and development of a mature .NET Framework ASP.NET MVC application which uses an Entity Framework repository pattern. Several developers have worked on it before me ...
2
votes
2
answers
3k
views
Where should helper classes/methods for transforming business data for the View be located
I have inherited a badly architected and organised ASP.NET MVC application, which is an online booking system for healthcare providers. It seems to have been designed with very few object oriented ...
4
votes
1
answer
966
views
Posts and Comments - how should I define them in domain driven design?
I am designing a blog in domain driven design. I don't know how I should define models: Post and Comment.
My database:
A user can see a post and related comments. So I think that Post model can be ...
-1
votes
1
answer
777
views
Two layers of DTO's for API's with Entity Framework
I am building an API which, amongst other things, needs to handle users. I am building it with C# 10 and .NET 6. In order to receive/return data in the API end points, I am using records. So for ...
1
vote
2
answers
81
views
Should I avoid putting Id's in a contract/response model?
Here is the scenario:
Let's assume that we have a Telephone and a Driver.
Here is the definition of the classes (Pseudocode):
Telephone:
{
Id: number,
[Unique] TelephoneNumber: string
}
Driver:
{
...
2
votes
3
answers
2k
views
Best way to generically convert SQL-Based classes to DTO using Class Name in C#?
I have a collection of classes in a SQL database that all share the same structure, and cannot be changed. They are similar to the example below.
I am using Entity Framework Core and would like to ...
0
votes
2
answers
703
views
How should design my entities when I sometimes need only a subset of fields?
I have a class that is mapped using Entity Framework. This class has dozens of fields, and in the database there are millions of rows for this class. The class looks like this
public class MyEntity
{...
0
votes
1
answer
276
views
Processing large number of messages in a thread-safe manner
I have the following use case and would like to implement it in a thread-safe manner. Think of a Stack Overflow-like web application.
Somebody upvotes a question.
A new event is sent to the message ...
1
vote
1
answer
210
views
Does injecting ILazyLoader inside entities in EF contradicts separation of concerns in design?
Microsoft suggests to inject ILazyLoader service inside entities in order to enable lazy loading manually in EF:
https://docs.microsoft.com/en-us/ef/core/querying/related-data/lazy#lazy-loading-...
-3
votes
1
answer
1k
views
Why running migration turns into timeout in a production environment?
I know this is a theorical question since i don't have code to or any logs to show, but i hope that someone can give me some idea on this question.
The problem in question was the following:
On my ...
0
votes
1
answer
34
views
Getting sums of multiple leveled relations efficiently
I'm currently building an API and a web app for an internal warehouse system using NET Core.
I have the core entity structure, that goes like this:
"Material" has many "MaterialSubtypes&...
0
votes
1
answer
3k
views
Where to put SaveChanges in unit of work?
For the sake of discussion, you can assume I'm using Entity Framework and a mediator pattern implementation in .NET.
I'm going back and forth trying to decide how to structure some of my data access ...
4
votes
2
answers
139
views
In the absence of code-contracts, what techniques exist to represent state invariants (e.g. "Customer with Orders loaded" with Entity Framework)?
In Entity Framework 6 and/or Entity Framework Core 3+, the code-first types generated by the scaffolding (or other code-generation tools, my preference is this T4 script) are mutable classes that do ...
1
vote
1
answer
747
views
DbContext lifetime in desktop app with SQLite
I am creating a small data-driven desktop application using .NET 5 with WPF, ReactiveUI, Dynamic Data, and EF Core 5. The app uses a local SQLite database to store all persisted state, and relies ...
0
votes
1
answer
605
views
In Entity Framework, how can I get a conditional sequence value?
I have entities in my application that require a unique human friendly identifier that include a sequence integer unique to a subset. For example, in project management software you might have a ...
0
votes
1
answer
2k
views
Right way of folder structure in MVC Project
I'm building a project with C# AspNet.Mvc. I'm using Entity Framework Core. It has Poco which maps in data from DB. On Mvc project itself i've got ViewModels folder where i have models topass between ...
1
vote
1
answer
2k
views
Is it considered a bad practice to include methods in classes that comprise an EF model?
I am working on a project that uses Entity Framework Core. I have a class which represents an entity on which I'm trying to perform validation. Is it considered a bad practice to include a Validate ...
-1
votes
1
answer
122
views
Strategy to make sure relevant cache records are expired on data update
In our database, we have around 150 different tables. However, there are a handful of them that are key, as in they get referenced pretty much everywhere. We also have quite a few reports that we pull ...
2
votes
2
answers
1k
views
C#: Use Double Await Cause Issues?
We have Application service Method, which extracts data from SQL database using Entity Framework Core .
Its Async method along with the Async Controller.
Service:
public async Task<IEnumerable<...
1
vote
1
answer
505
views
Designing asp.net core web api to add sub classes/specialized objects
I have not worked with EF for a while.
As an exercise, I am writing a core web api that allows keeping track of a user medias.
A media can be a postcard, a photo album, a recording, a book...
I would ...
1
vote
2
answers
2k
views
repository pattern, using the domain object as data access object
I'm very puzzled by a specific part of the repository pattern that seems simple but turn out to be tricky.
I took this great explanation of this topic by Mosh Hamedani; it's a C# implementation of ...
1
vote
2
answers
1k
views
Should an AggregateRoot not be a database Entity?
TLDR: Does using DB objects as my AggregateRoot lead to bloated God objects. In comparison to the issues I see in using separate DbObjects and DDD objects.
I'm trying to bring together my ...
0
votes
1
answer
81
views
Move monolith to Event Streaming in one step or multiple steps?
I have been the sole developer on a project for the past eight years. Right now it's one big monolith, but at this point it's really three separate apps, and those really need to be broken down as ...
0
votes
0
answers
528
views
Net Core: Solutions to Update History Tables in Application Design
Our company did not properly design Address Record Code Module. Developers are updating Address SQL table with Multiple Service Methods, and are not updating AddressHistory Sql table. They're asking ...
1
vote
1
answer
2k
views
Logging to database in ASP.NET Core Entity Framework Core application
I have an ASP.NET Core Entity Framework Core application and I want to implement my own custom logger. I don't want to use ready solutions like NLog or Serilog.
I added a new class library project ("...
1
vote
0
answers
374
views
Should I use a Web API between a client and Entity Framework?
I am creating a database that will keep track of my company's clients, and an app that will allow users inside the company to read/update/etc. the database. I'm using code-first EF Core to manage the ...
5
votes
3
answers
3k
views
Are methods a bad practice on .NET Core EF entity classes?
Say you have the following entity that represent an exact resource from a table, we're talking .NET Core with Entity Framework Core, code-first approach.
public class Person
{
[Key]
public ...
1
vote
2
answers
870
views
Entity Framework and Domain Driven Design Testability
I'm using a DDD approach for the Domain classes. Although, I have a problem on my design, that I'm handling it now but didn't have a good idea to over tackle it.
My Architecture is the follow one:
- ...
6
votes
3
answers
14k
views
Is unit of work pattern really needed with repository pattern
I am trying to use EF6 with my project. I just watched Repository Pattern with C# and Entity Framework, Done Right | Mosh video. I understand the necessity of Repositories but I still don't understand ...
0
votes
2
answers
225
views
Services injected with factories
I face an issue where I want to inject Entity Frameworks DbContext into a service class, in a WPF application. The problem is that the service classes are instantiated and contained by the view models....
0
votes
1
answer
66
views
data model design of a store net sales and earnings
I've designed my app so it stores the data of each sale in the following way: each order contains different products so for each product in an order a table stores the quantity(of the product) , net ...
0
votes
3
answers
875
views
Need advice on reporting with big amounts of data
I have a monolith application in .net core 3.0 with entity framework core 3.0. using:
a table with ~3 million records. Its structure is BusinessUnitId | ProfileId | Amount(it has more fields, but ...
1
vote
1
answer
58
views
Pattern for schema split across sources
I was not sure how to title this question, but bear with me.
My company is building a new product and for it we will use a third-party service (let's call it ENB for short) to be responsible for many ...
8
votes
2
answers
8k
views
Avoiding Repository pattern - implementing Onion Architecture with DbContext only
I am trying to follow the Onion Architecture to design my application where I have the following layers -
Domain Layer: is the inner-most layer and defines repository interfaces
Infrastructure ...
2
votes
1
answer
142
views
Application Security Trimming vs Database Security Trimming
We have a fairly complex Meetings Management solution which would have one meeting to contain different agendas which would contain some tasks and also documents, etc. There are also different roles ...
0
votes
1
answer
147
views
Best practice for populating a property of an entity object which requires a second database call
I'm running a commercial accounting software packages which uses a SQL server database. I've also developed a WPF application which is basically a slimmed down version of the commercial software.
...