Questions tagged [entity-framework-core]

Entity Framework (EF) Core is a lightweight, extensible, and cross-platform version of the popular Entity Framework data access technology.

Filter by
Sorted by
Tagged with
0 votes
0 answers
41 views

Structure of a blog-application in ASP.NET MVC

I'm trying to make a small blog-application in .NET 6 MVC (+ EF), but I'm a bit stuck on designing the overall-architecture of the application. Especially when ViewModels are involved. This is (a part ...
user avatar
  • 1
-1 votes
2 answers
75 views

Using default implementations to superpower flags enums with C# [closed]

I would like to share this post with the community since at first glance it is very promising. Storing flags in the database is something that I have been interested in doing for a while since it ...
user avatar
  • 199
3 votes
2 answers
111 views

RawSqlQuery minimizing risk of field name confusion

Is there a way to make the following code more maintainable? ...
user avatar
  • 423
3 votes
1 answer
69 views

EFCore Monitor Interceptor with logging queries

I created a SqlMonitorInterceptor that will check the execution time of queries and log errors. The main idea is to log queries in such a way that they can be easily copied into SQL Server Management ...
user avatar
  • 817
3 votes
2 answers
99 views

Get a list of the 25 most popular items on an E-Commerce site

I have a few lines where I am trying to get a list of the 25 most popular Items sold on an E-Commerce web site. The code works but I would like hints on how to optimize it. ...
user avatar
  • 487
0 votes
2 answers
91 views

Finding items involving a particular category

I have a Item Service that is Called from an Asp.Net Core API Controller. The query gets all items in a particular category for display on an eCommerce web site (reactjs). The controller only returns ...
user avatar
  • 487
0 votes
0 answers
53 views

Decompose URL components and store into a database

I'm writing a web crawler, and want to store the parts of a URL to a database using Entity Framework. Instead of trying to parse a URL into its component parts myself, I thought I could inherit from ...
user avatar
1 vote
2 answers
104 views

Database dynamic query

I am working with C#, Npgsql, EF Core and Postgres. I ...
user avatar
  • 193
0 votes
1 answer
95 views

How do I optimize my GetChildren method

UPDATED I have a POCO class that is populated with _context.Categories.Load(): ...
user avatar
  • 487
-3 votes
1 answer
89 views

Swagger doc and Entity Framework include not working [closed]

I tried to create a .Net core API using Microsoft Documentation but I ran into some issues. The app is working but only for a "single" table. The includes are empty. ...
user avatar
1 vote
2 answers
110 views

Optimizing database access using LINQ [closed]

I have the following method that I am trying to optimize. Currently, the method works great, however, it takes a little over 3 hours to complete. I feel like, using some nifty LINQ joins, it should be ...
user avatar
  • 188
3 votes
1 answer
2k views

A simple method to execute Entity Framework Core queries in parallel

As you might know, EF Core does not support executing multiple queries in parallel on the same context using something like Task.WhenAll. So you have to write this ...
user avatar
  • 178
1 vote
0 answers
119 views

How to flatten the nested try-catch block in F#?

How to flatten the nested try-catch block in F# for the following code? I am using EF Core with F#. The nested is required because I need to Rollback the transaction if there are errors in saving or ...
user avatar
2 votes
2 answers
559 views

Entity Framework Core verify SaveChanges count

I am using ASP.NET Core 3.1 and have been assigned a task to verify the count of changes done using SaveChanges(). It is expected that the developer should know how ...
user avatar
2 votes
1 answer
737 views

Entity Framework Core DbFunction for square root

I'm porting my site over from .NET Framework / MVC 5 / EF6 to .NET Core 3.1 MVC / EF Core. MSSQL Server for the database. EF6 has SqlFunctions of which one method ...
user avatar
  • 33
1 vote
1 answer
55 views

Many to Many Relationship using EF Core

I've implemented Many-To-Many relationship and wonder if this is the optimal way for it. Since I do not have extensive EF Core experience I would love if someone with more experience could check it ...
user avatar
  • 175
7 votes
2 answers
2k views

ASP.NET Core 3.1 AddHttpClient call that includes a call to the database

So, I have an ASP.NET Core 3.1 web site that makes occasional calls to a vendor's RESTful API. I use the HttpClient class to perform these calls. Currently, the ...
user avatar
0 votes
0 answers
35 views

Handling disconnected entity scenario in Entity Framework Core

As some you you may know, handling disconnected entities in EF can be a bit of a headache. After a really long weekend, I managed to make it work for my use case and refactor the code to the best of ...
user avatar
1 vote
1 answer
169 views

Three-way join in Entity Framework Core to retrieve all roles that a user has

I'm very new to Entity Framework Core, so I'm concerned about whether I've done this query in the most efficient way possible. The database I'm querying looks like this: Basically, ...
user avatar
6 votes
2 answers
125 views

Many-To-Many movie director system

I have the following relationship in EF Core 3.1.1 (Many-To-Many): ...
user avatar
  • 202
1 vote
1 answer
663 views

ASP.NET EF seed one to many relation

I am creating a simple model relation in ASP.Net core. My model relations are like this: A user can have many posts A post can have many comments A user can have many comments Now I am trying to ...
user avatar
  • 113
5 votes
1 answer
91 views

Prepare and export data to MS Word file

The task of the code that is presented for review is to prepare all the data for the export of the selected contract and create a file on this basis. This is one of the first experiences with a ...
user avatar
  • 294
3 votes
1 answer
375 views

Bank ATM Mockup App

This is a follow-up on bank ATM mockup app in .NET Core framework and Entity Framework Core. I have 2 user interfaces: Console and Web. Previously I have UOW and repository layer but I have removed ...
user avatar
0 votes
0 answers
491 views

Bank ATM App Mockup - Implementing Domain-Driven Design (DDD)

There is a follow-up on this question. I have created this bank ATM app mockup which I believe implement some Domain-Design Design layered architecture, repository pattern and uow pattern, if not ...
user avatar
6 votes
2 answers
274 views

Asynchronous IBAN API with validation

I am working on an iban api which is about saving the iban of some members after (iban validation) in a database. The code is split between Domain (entities, behaviour for iban validation), Database ...
user avatar
  • 1,101
6 votes
1 answer
18k views

Get all children recursively in Entity Framework Core

In Entity Framework Core we can have recursive entities. But we cannot do an "Include" for these recursives (can we?). So I wrote a Get-method that does it for me: ...
user avatar
2 votes
0 answers
65 views

Querying based on condition

I am using Entity Framework Core as ORM in my ASP.NET Core 2.1 project. I want to perform server-side pagination in Career Controller for getting list of careers. I have a model which looks like: <...
user avatar
1 vote
0 answers
82 views

Persist payload containing multiple items using EF Core Performance Improvements

I have an .NET Core EF application, setup as Database first, that is supposed to take in a payload containing items to be persisted to my database. They payloads can be huge containing multiple "...
user avatar
7 votes
1 answer
156 views

Retrieving the IDs of entries to be deleted from a table

Business logic It would take us too far to explain the whole business case behind this code, so I'll try to be as succinct as possible. There are Persons, and ...
user avatar
  • 10.6k
-1 votes
1 answer
110 views

Handling Entity Framework in connected mode within Windows Forms [closed]

I know the difference between the Entity Framework connected mode vs disconnected mode. In connected mode we do all the stuff inside one single DbContext instance. ...
user avatar
4 votes
3 answers
204 views

Web-app for tracking containers

Nowadays I am learning Domain Driven Design intensively. I am reading the book called Domain Driven Design by Eric Evans, and at the same time I try to apply the knowledge on a real life project I ...
user avatar
  • 289
8 votes
1 answer
148 views

Shopping cart purchase method in service layer

The following is a class in the service layer of an ASP.NET Core web application, which currently contains a single method: PurchaseCart. The intention is that an ID is passed in to a "shopping cart" ...
user avatar
0 votes
2 answers
3k views

Is it fine to use my domain model as DTO (Entity Framework Core)? [closed]

I was reading about anemic data models and rich domain models in DDD. I don't want to follow DDD completely but take rather pragmatic approach and just take some concepts out of it because clean ddd ...
user avatar
  • 227
7 votes
1 answer
3k views

Preventing duplicate key errors in EF-Core InMemory provider through locking

I have a rest service on Azure AD that calls other rest services. They use AzureAd authentication and AuthContext with a custom TokenCache that stores each users ...
user avatar
4 votes
1 answer
3k views

Linked List implementation Entity Framework Core

I am trying to create a data model where there are Document entities, which need to be in a defined order to each other. Think of an article that has sections which ...
user avatar
2 votes
1 answer
1k views

Web Service that gets data from multiple tables in a database using EF Core Database-First approach

I have never created a web service before. I followed most of this Pluralsight tutorial to give me an idea of how to create one using ASP.NET MVC along with .NET Core 2.0 and Entity Framework Core. ...
user avatar
  • 123
1 vote
1 answer
1k views

Configuring certificate signing for development and production environments

The below code works but there's a lot of duplication I wonder if I can get around. I would like to be able to use .AddDeveloperSigningCredential(false) if in ...
user avatar
  • 175
1 vote
0 answers
489 views

Selecting coins with alert count by using a subquery

I have a table called alerts and is related to a table called coin (coin can have many alerts). I would like to return a list of alerts but also return a subquery count of how many alerts that coin ...
user avatar
  • 163
1 vote
0 answers
83 views

Loop through records, change property of records, send mail for each

I am trying to basically do the following Get record from db. Loop through records and send mail out for each record. Update database records. I would like to know what is the most optimal way to do ...
user avatar
  • 163
3 votes
1 answer
9k views

EF entity, extended with partial classes for actions

Me colleague and I recently had a discussion on good practices in EF. So I showed one of mine. He said it is a little bit muddler. My practice consists of modifying the autogenerated class in a ...
user avatar
  • 33
2 votes
0 answers
2k views

Create a hierarchical tree with ordering field with entiry framework core

This is my model: ...
user avatar
  • 121
1 vote
1 answer
934 views

EF Core Complex Query Method

The code is returning reviews based on users like status order. It seems it executes a lot of SQL queries, so do you think it can be simplified and can it be a headache to server performance? ...
user avatar
1 vote
0 answers
395 views

ASP.NET Core basic login implementation

I'm fairly new to ASP.NET Core, I've used webforms for years so I naturally want to cling to things I did with webforms. The following code works, but I'm wondering if it can be cleaned up with ...
user avatar
1 vote
0 answers
740 views

BaseRepository for EntityFrameworkCode

I want to create some BaseRepository for EntityFrameworkCode and I've tried construct this Repository based on code from ...
user avatar
  • 111
3 votes
1 answer
1k views

Enum synced with Database

Our database has several tables that have a value that can be one of 4 things, so we made these columns instead have an id column with a foreign key to an enum table with an id and a value column to ...
user avatar
2 votes
1 answer
325 views

Applying EF core in Universal Windows Apps using a large database

I am building my UWP app and really stuck in the architecture. For the past few days, I have been reading MVVM, Entity Framework, SQLite, Code First, etc and I am confused how I will implement ...
user avatar
  • 123