Questions tagged [entity-framework]
An ORM built by Microsoft and is available as part of .Net framework 3.5 and later.
375
questions
0
votes
2
answers
112
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
578
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 ...
0
votes
3
answers
410
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
122
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
930
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
1k
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 ...
0
votes
1
answer
419
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 ...
1
vote
2
answers
678
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 ...
1
vote
2
answers
2k
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
734
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
549
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
75
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
929
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
247
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
206
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
157
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
587
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
32
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
2k
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
120
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
553
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
431
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
996
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
857
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
106
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
920
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
352
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
1k
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
765
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
66
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
466
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
258
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
2k
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
692
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
10k
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
170
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
58
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
502
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
54
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
6k
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
124
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
97
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.
...
2
votes
1
answer
6k
views
How to avoid circular references with EF Core and Global Query Filters?
We're working on building a multitenant application, and we're using Entity Framework Core as our base data provider. With EF Core, you can use Global Query Filters to define custom filters that apply ...
1
vote
0
answers
54
views
"Add-On" Projects and ASP.NET Core with Entity Framework
I've created a .NET Core MVC product with Entity Framework, and am being tasked with creating "Add-on" products, which give CRUD operations to more tables, but use the same library functions and UI.
...
2
votes
2
answers
237
views
Different types of account transactions
I'm working on a system where users have different types of 'Accounts' of the financial type. I'm struggling to come up with a design that works.
Background
A user has 2 types of accounts: A 'tab' ...
4
votes
3
answers
3k
views
DataAccess Layer coupling with Domain Layer
We have an issue with how the implementation of the Data Access layer (EF6 Includes more specifically), influences the behavior of our Domain layer.
A theoretical example to illustrate:
Application ...
2
votes
3
answers
267
views
Choosing between derived classes and adding an additional property in entity framework
I have the following StudentGroup class:
public class StudentGroup
{
[Key]
public int Id { get; set; }
//the set of peers who will review the work of the StudentGroup
[ForeignKey("...
1
vote
1
answer
347
views
Call library functions with varying number of inputs while keeping API simple
For a ASP.NET Core application, I'm using a library which performs calculations using objects that have a similar interface but their constructors use different inputs. The inputs are market prices ...
3
votes
2
answers
666
views
Is making your ORM DAO a subclass of your Domain Model object a viable strategy?
I am trying to separate my domain model and associated business logic from my persistence model, particularly such that the domain model has no dependency on the ORM. One apparent way to do that was ...