Skip to main content

Questions tagged [entity-framework]

An ORM built by Microsoft and is available as part of .Net framework 3.5 and later.

Filter by
Sorted by
Tagged with
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 ...
Álvaro García's user avatar
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 ...
Afshar's user avatar
  • 223
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 ...
CrystalBlue's user avatar
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 ...
Mandelbrotter's user avatar
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 ...
cargt4's user avatar
  • 19
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 -&...
Gersalom's user avatar
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 ...
Samuel's user avatar
  • 723
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 ...
pakerinjo's user avatar
-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 ...
Szyszka947's user avatar
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 ...
Veverke's user avatar
  • 471
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"...
Subliminal Hash's user avatar
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 (...
Sam's user avatar
  • 65
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 ...
Álvaro García's user avatar
-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 ...
J.Paravicini's user avatar
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 ...
Ian's user avatar
  • 131
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 ...
Kyohei Kaneko's user avatar
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 ...
Aleksander Chelpski's user avatar
-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 ...
Jakob Busk Sørensen's user avatar
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: { ...
Replay's user avatar
  • 109
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 ...
AnotherDeveloper's user avatar
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 {...
Ben Rubin's user avatar
  • 151
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 ...
robotron's user avatar
  • 767
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-...
Ahmad's user avatar
  • 121
-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 ...
Nmaster88's user avatar
  • 167
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&...
Valhaal's user avatar
  • 13
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 ...
Alexander Trauzzi's user avatar
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 ...
Dai's user avatar
  • 678
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 ...
wired_in's user avatar
  • 332
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 ...
Superman.Lopez's user avatar
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 ...
Mattew's user avatar
  • 9
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 ...
M.R.'s user avatar
  • 63
-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 ...
Riz's user avatar
  • 206
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<...
user avatar
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 ...
Veverke's user avatar
  • 471
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 ...
AgostinoX's user avatar
  • 841
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 ...
David C's user avatar
  • 273
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 ...
Jhorra's user avatar
  • 147
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 ...
user avatar
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 ("...
Shrodinger's user avatar
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 ...
Craig Brown's user avatar
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 ...
J.C.'s user avatar
  • 79
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: - ...
joseFrancisco's user avatar
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 ...
Mansur Ali Koroglu's user avatar
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....
Jakob Busk Sørensen's user avatar
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 ...
Diego Piscoya's user avatar
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 ...
Jamil's user avatar
  • 131
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 ...
Jokab's user avatar
  • 141
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 ...
atiyar's user avatar
  • 203
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 ...
windfly2006's user avatar
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. ...
Troy Frazier's user avatar

1
2 3 4 5
8