Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
13 views

Entity Framework Core logging - can't see how the generated query is bringing back my data

My simple test app, which I set up to diagnose another issue I was having, seems to be retrieving associated data from a table that I wasn't expecting, and when I turn on logging I can see no ...
Distopi's user avatar
1 vote
1 answer
23 views

EF Core : add object to set with existing child objects causes duplicate key exceptions

I have these models: public class A { public Guid Id { get; set; } public string Name { get; set; } public B Child { get; set; } } public class B { public Guid Id { get; set; } ...
Lee's user avatar
  • 248
-2 votes
0 answers
32 views

An alternative to using repositories with the Entity Framework Core [closed]

I use the repository pattern to retrieve data from the database, and now some of my query handlers receive 5 or more repository classes as arguments in their constructors. I am not a fan of this ...
Alseratia's user avatar
1 vote
1 answer
20 views

How to query with LINQ a dictionary property in EF Core with Cosmos DB provider

I have a class Entity mapped with EF Core to a Cosmos DB container. The class has a property Labels of type Dictionary<string, string>. How can I find all instances of that class that have say ...
Valo's user avatar
  • 2,020
3 votes
1 answer
41 views

array_agg in EF Core 6

I'm working with EF Core 6 and PostgreSQL, and I need to construct a query that efficiently retrieves author names along with an array of their book titles. My database schema: Books BookId (number) ...
AmitHaritan's user avatar
1 vote
0 answers
31 views

Always encrypted with Entity Framework Core

We have a .NET Core application with EF Core 7 and code-first approach. We have taken the below steps: Create table in the database Encrypt columns using Always Encrypted - with keys in Azure Key ...
Shahrukh Sayyed's user avatar
0 votes
1 answer
30 views

EF Core - Multitenancy using a dynamic global filter

I'm trying to implement multitenancy in an app with a single database. I introduced a middleware that fetches the TenantId per request and a global filter to modelbuilder that filters all relevant ...
user27378175's user avatar
2 votes
1 answer
33 views

DBContext pooling isn't working with Interceptors and healthchecks

I had the need to optimze some sql queries with "OPTION (OPTIMIZE FOR UNKNOWN)". I therefore added a custom Interceptor like this: public class QueryHintInterceptor : DbCommandInterceptor { ...
UNeverNo's user avatar
  • 581
0 votes
2 answers
68 views

Does EntityFrameworkCore async method use different thread than the one which DbContext is created?

DBContext db = new DbContext() await db.Parents.FirstOrDefaultAsync(p => p.Id == id); As I know that DBContext is not thread-safe and it does not allow multiple threading, but why can we use await ...
Robin Sun's user avatar
  • 1,546
0 votes
1 answer
27 views

.NET Aspire : how can I remove an migration that has already been applied to the database using Entity Framework Core

I'm working on a .NET Aspire project that includes: A PostgreSQL component with Entity Framework Core using code-first approach A persistent data volume A separate background service for applying ...
Yash's user avatar
  • 1
0 votes
0 answers
25 views

EF Core manually removing foreign key

What kind of fallout can I expect from manually removing the foreign key constraint generated in EF Core? We are trying to normalize a table to be used on multiple tables in our system below is a ...
Orangesooda's user avatar
0 votes
0 answers
40 views

How to get current User outside of Controller in another layer

In ASP.NET Core 6, I need to get the current user in service layer This is code: public class ServiceModel { private readonly IHttpContextAccessor accessor; public ServiceModel(...
MrMustafa022's user avatar
0 votes
2 answers
45 views

EF Core 8 database first with Identity User tables

I already have a database which contains identity user tables (AspNetUser, AspRole,...). I am using DB first to generate Models, I've configured every necessary services in program.cs. The project ran ...
tan truong the's user avatar
0 votes
0 answers
25 views

EntityFramework Core 8: IRelationalValueBufferFactoryFactory interface is missing after upgrade from EF Core 6

After upgrading the project from .NET 6 to .NET 8 and updating Entity Framework Core nuget-package from version 6 to version 8, I encountered the following error related to materialization of data ...
Mukul Garg's user avatar
1 vote
0 answers
75 views

Get value from two tables with only one model class

I have a model looking something like this: public class Order { public int Id { get; set; } public string Name { get; set; } public int TypeId { get; set; } public string TypeName { ...
Fakima's user avatar
  • 21
0 votes
1 answer
69 views

Asynchronous Query execution in Entity Framework Core C#

I want to understand whether the asynchronous execution happens same as C# code as in EFCore Queries. Let's suppose I have the following queries: var result1 = dbContext.Customers.Where(x=> x....
Ghanshyam Mirani's user avatar
-2 votes
0 answers
28 views

Applying structural changes to database tables during execution and after application release

How can I write a routine for an application that, after its release, can dynamically add, initialize, or delete one or more fields in a database table or tables, without storing the fields and data ...
Jahed Kabiri's user avatar
-3 votes
0 answers
19 views

.NET command-line tools EF Core not updating correctly [closed]

I am trying to update my dotnet ef tools, and for some reason it doesn't work. I've tried from both Visual Studio and Power Shell. No matter what commands I use, it will still keep itself on this D@mn ...
Marcel James's user avatar
1 vote
3 answers
71 views

Getting the Column Name mapping component of an EF Core Class property?

I have the following EF Core class: public partial class myClass { public string ID { get; set; } [Column("Team 17")] public bool? Team17 { get; set; } [Column("Team 158&...
RoastBeast's user avatar
  • 1,111
0 votes
1 answer
10 views

Entity Framework Core 8 and HierarchyId error on add-migration

I have got this error trying to add a new migration while adding a new entity with a HierarchyId property Unable to create a 'DbContext' of type ''. The exception 'The 'HierarchyId' property 'Node....
Mainumbi's user avatar
0 votes
1 answer
16 views

Reuse Entity in Entity Framework Core

I wish to create the following database using Entity Framework Core. I am using Entity Framework Core with SQLite and WinUi 3 with the MVVM toolkit. I am having trouble with getting the Address part ...
Nuvolari's user avatar
  • 1,153
0 votes
0 answers
29 views

How do I map denormalized records into one EF Entity with collections?

(I don't own this data so I can't add constraints or properly normalize it) I have a denormalized table where I have many records with the same primary Id and those records each contain what should be ...
Dave Matney's user avatar
0 votes
0 answers
34 views

EF Core not able to run if a trigger exists on a table

I have a .NET 8 Function App that connects to an Azure SQL Server. It uses Entity Framework Core to insert/update to a table. Recently another team member added a trigger on a table that I'm ...
Caverman's user avatar
  • 3,597
0 votes
1 answer
47 views

How to add entities to a join table using Entity Framework Core

I have two entities that share a many-to-many relationship (Agent and Patient). Entity Framework Core by default will create a join table (AgentPatient) for me. I'm having trouble adding patients to ...
Daniel Ishida's user avatar
0 votes
0 answers
35 views

Mapping collection of primitives to JSON in EF Core

I'm using EF Core with Postgres. An entity includes these properties, which I store as JSON: public ICollection<long> Foo { get; } public IDictionary<long, long> Bar { get; } This ...
lonix's user avatar
  • 18.5k
0 votes
1 answer
67 views

How to fix Razor Pages CRUD Scaffolding Error

I'm running VS 2022, and have a Razor Pages site created. I tried to scaffold Razor CRUD pages and received the following error: and this is what outputted: Finding the generator 'razorpage'... ...
kyros's user avatar
  • 153
0 votes
0 answers
28 views

EF Core7 throws "Object reference not set to an instance of an object" error when HasColumnName added

I am using EF Core 7.0.7 with .NET 8. I try to update a configuration as follow Old builder.Property(c => c.AddressId).IsRequired(); New builder.Property(c => c.AddressId).IsRequired()....
Ben's user avatar
  • 1,191
0 votes
1 answer
52 views

OrderBy method does not work after EF Core 3.1 upgrade

public virtual async Task<IPagedList<TEntity>> PageAsync(Expression<Func<TEntity, bool>> filter = null, Expression<Func<TEntity, object>> sortingKeySelector = ...
Zoran G's user avatar
  • 71
0 votes
1 answer
34 views

EF Core map both a table and a view based on the table

I have a table and a view based on the table. They share exactly the same config except for an additional aggregate column on the view. Let's call them Order and OrderExt. I want to use my ...
statler's user avatar
  • 1,371
0 votes
1 answer
49 views

Entity Framework Core : filter by 3 fields

I'm trying to query some subscriptions from the database using Entity Framework Core. A subscription is equal to another subscription if the userId, the NotificationType and the Channel match. I'm ...
Jaime's user avatar
  • 143
0 votes
0 answers
67 views

EF Core 6 Arbitrarily Adding 'WHERE 1 = 0' Clause

I have moved my production code from an on-premises server to an Azure server. I noticed that most queries are returning 0 results, but when counting the rows, they return the correct count. After ...
Abdulaziz Burghal's user avatar
0 votes
1 answer
78 views

.NET Core / Entity Framework Core not updating, seemingly referencing a migration history database even when it doesn't exist

dotnet ef migrations add X This works and adds three files (if there are no other migrations at all) in the migration folder, X.cs, X.Designer.cs and QuizzDbContextModelSnapshot.cs. dotnet ef ...
AME's user avatar
  • 43
2 votes
1 answer
36 views

Adding a unique constraint that includes a nullable value

I have the following entity model class: public class RoutePermission { public Guid? UserId { get; set; } public Guid? DistrictId { get; set; } public Guid RouteId { get; set; } public ...
Shmuli Adelman's user avatar
0 votes
2 answers
30 views

Source generated ValueConverter with EF Core

I have wrote my own source generator which generates some boilerplate converters, including a value converter for EF Core. Here's a short example: [GenerateConverters] public partial record Height(int ...
DirtyNative's user avatar
  • 2,804
-2 votes
1 answer
102 views

How to fix "SqlException : A network-related or instance-specific error occurred while establishing a connection to SQL Server. (error: 26) "

My scenario I have a new ASP.NET Core web application and I've connected it to my locally running SQL Server database. I can add migrations and update-database from package console manager without any ...
Arj's user avatar
  • 85
0 votes
1 answer
100 views

What is the correct way to handle models and entities in clean architecture? [closed]

So I'm trying to set up all the basics for a new .NET application. It's a Blazor app, to be created with clean architecture and code-first EF Core. In my domain layer I defined some entities which ...
maaax's user avatar
  • 31
0 votes
2 answers
44 views

C# & EF Core : multiple entities of same type relations

I have EF Core (7.0.20) Member entity like this: public class Member : BaseEntity { public Warn FirstWarn { get; set; } public Warn SecondWarn { get; set; } public Warn ThirdWarn { get; ...
Oleg's user avatar
  • 1
0 votes
1 answer
43 views

Why string property must be declared as nullable string in Entity Framework Core when corresponding database table column is nullable

Entity Framework Core version is 8.0. Here is my model. public class Item { [Key] public long ItemId { get; set; } public string KeyNumYear { get; set; } ... } In ...
Robin Sun's user avatar
  • 1,546
0 votes
1 answer
28 views

EF Core - Configure row version for all entities that derive from a base class

In order to have a row version on an entity the documentation guides to do this: class MyContext : DbContext { public DbSet<SomeEntity> SomeEntities { get; set; } protected override ...
Parsa99's user avatar
  • 388
-1 votes
0 answers
40 views

Entity Framework Core: error instance of entity type cannot be tracked

I'm saving a list of records (55,000) at single time using Entity Framework Core with this code in .NET 8: await _context.Associatedjobs.AddRangeAsync(Allassociatedrecords); await _context....
Yogesh Shinde's user avatar
2 votes
1 answer
42 views

Adding related entities - Concurrency Exception

I'm working on a management system project in ASP.NET Core and I've encountered an issue with saving a related entity to the database. I'll describe the problem using a simplified example. I have two ...
ZML's user avatar
  • 23
0 votes
0 answers
37 views

Issues with connection string during saving of data in .NET Core project

I am Mac user (old Mac, not M1). I have a .NET Core application, and I have Docker where I downloaded SQL Server image and I also have Azure Data Studio. In my Azure Data Studio, I can log in to my ...
denisaemailova's user avatar
0 votes
0 answers
59 views

Upload Multiple Images to File Path and Database

I'm using ASP.NET Core MVC, C# and EF Core code-first. I'm running into an issue that is not allowing me to upload multiple files to my folder and the corresponding path to the database table. The ...
user18776105's user avatar
0 votes
0 answers
43 views

Is there a way to create foreign keys at runtime in Entity Framework?

For background, let's say I have two classes: public class OrderType1 : ModelBase { public string Customer { get; set; } } public class OrderType2 : ModelBase { public string Customer { get;...
Thomas's user avatar
  • 43
0 votes
1 answer
35 views

Does EFCore Where( ... set.Contains(...)) care whether Set is List or HashSet?

Suppose I an using EFCore to query a SQL DB, and I write: myTableDbSet.Where(entity => filterSet.Contains(entity.Id)) Then does it make any difference (e.g. to performance) what the concrete type ...
Brondahl's user avatar
  • 8,387
2 votes
1 answer
63 views

Mapping multiple columns value to dictionary entity property

I have an existing on-premises application that works without Entity Framework. Each customer has its own installation and different SQL Server database instance. All the databases have the most of ...
fedegiamporcaro's user avatar
0 votes
0 answers
35 views

Is it possible to query, alter, and update data in EF Core during a migration up and also to reverse that in migration down?

We want to modify a table in our database by adding a column and then updating all of the records in that table. For simplification, we are adding ValueB as the new column: ID ValueA ValueB (new ...
myermian's user avatar
  • 32.4k
0 votes
2 answers
50 views

ASP.NET Core Razor pages web app: in the OnPost the request has data in the Items list but in the OnGet the list is empty

What am I doing wrong? I have not used ASP.NET Core or EF Core in a long time so I'm relatively new to it. When I debug with breakpoints in the OnPost the Items list has data, but when the page is ...
Zinox's user avatar
  • 519
1 vote
1 answer
52 views

How to make .OwnsOne() objects not null by default?

So I've inherited an app that I've recently upgraded from .NET Core 2 to .NET 8. It uses entityframework and a lot of .OwnsOne(). After updating I ran into the problem that, in the previous version of ...
Ja Da's user avatar
  • 466
0 votes
1 answer
44 views

EF8 handling string nullability: required, set vs init

How should string nullability be handled in EF8? Should I use the required keyword? Also should I choose set; over init;? I remember there were some issues with init; in .NET 6. public class ...
nop's user avatar
  • 6,007

1
2 3 4 5
461