Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
29 views

Strongly typed id in EF Core while projecting to some model

I try to query Postgresql DB on models with strongly typed ids and project to a model. Cannot understand why query doesn't work. It throws this exception: Unhandled exception. System....
Simeon Iksanov's user avatar
0 votes
0 answers
15 views

Error creating new instance of ef core context in new Inventor 2025 addin

I am creating an addin for Inventor 2025 using its own vb.net addin template. It needs to interact with a sql server database (load drawing info and saving parts lists). When I create the new instance ...
Adrian Loughman's user avatar
0 votes
0 answers
28 views

How to force a many to many relationship to be queried as OUTER JOIN in Entity Framework

I have this structure in SQL Server: Look at the expanded tables. CampoAdicionalPorPersona table is a navigation table between Persona and CampoAdicional (many to many relationship). When I do this ...
jstuardo's user avatar
  • 4,554
1 vote
0 answers
26 views

EF Core migration - nullable property gets turned into a non-nullable column

I have a model class OverAllStatus with this property: [Column("OverallStatusID")] [StringLength(50)] public string? OverallStatusId { get; set; } However, in the ContextModelSnapshot, the ...
user28752003's user avatar
0 votes
0 answers
30 views

EF Core does not change the table schema when the API is at runtime

I'm developing a multi-tenant ASP.NET Core Web API project and I use EF Core 8 as my ORM and SQL Server. The project supports several tenants and I need to create the databases at run time and change ...
rj-'s user avatar
  • 21
-1 votes
1 answer
54 views

ASP.NET Core & EF Core : concurrency exception not thrown despite working rowversion

This is part of my method which creates reservations of books: var book = await _context.Books.FirstOrDefaultAsync(b => b.Id == id); if (book == null || !book.IsAvailable) { return ...
johny_walker's user avatar
3 votes
2 answers
64 views

Does Entity Framework Core support queries based on a table of custom values?

I'm using a T-SQL query like SELECT WeekStart, (SELECT COUNT(DISTINCT UserId) FROM Logins WHERE Timestamp >= WeekStart AND Timestamp < DATEADD(wk, 1, WeekStart)) ...
Paul B.'s user avatar
  • 2,525
0 votes
1 answer
52 views

Entity Framework query filter is not being applied

I am applying a query filter globally on all entities that inherit from EntityBase class: // filtering not deleted items Expression<Func<EntityBase, bool>> filterExpr = eb => !eb....
Marko Sami's user avatar
0 votes
0 answers
14 views

Understanding EF Core Add-Migration

I tried finding this the source code to investigate how it finds the context but no luck with source code so far. Here is a my project structure: EXE App containing EF Core Tools Class library ...
Iftikhar Ali's user avatar
1 vote
1 answer
26 views

Data Logic at Facade level

I have 2 Db's with their own projects, data services and controllers. We have methods for them at the facade level which can use either Db. I have a situation where I need to write something to both ...
Sean McKinney's user avatar
1 vote
1 answer
63 views

Comparing decimals within a LINQ query using a SQLite-database fails with operators but works with .CompareTo

In my SQLite database, I have a table foo that contains a column bar that is of data type decimal. I want to retreive all rows, where the value of bar is > 100. If I try to execute the query like ...
mamen's user avatar
  • 1,667
1 vote
1 answer
23 views

Resolving TPH Inheritance and Migration Issues in Entity Framework Core with Multi-Project Architecture

I’m working on a multi-project architecture with models and data access layers in separate .csproj files (These are Class Libraries.) Using EF Core 8 and TPH inheritance, I encounter the following ...
Acetone9177's user avatar
0 votes
1 answer
43 views

Using a single DBContext with a model for multiple schema generated at runtime in EF Core

Considering a sample application with the data structure: Calculations: Id, Value The application should update the database structure at runtime to add a new table recognized by schema. Then it ...
Mahdi's user avatar
  • 141
0 votes
2 answers
28 views

how to set entity's property order to mapping migrations dbscript columns order?

1.I have a BaseModel class: public class BaseModel : BaseDeletedModel { [Key, Column(Order = 0), MaxLength(50), Required] public string ID { get; set; } } public class BaseDeletedModel { [...
Xt Yuan's user avatar
1 vote
2 answers
45 views

Query jsonb array in postgresql table with EF Core

I would like to return all the rows that contains a price higher than 123: // Entity Table1 [Column(TypeName = "jsonb")] public List<NewPrice> HistoryPrices { get; set; } public class ...
kevinob's user avatar
  • 667
-1 votes
0 answers
38 views

This method or property cannot be called on Null values [duplicate]

I get this error: fail: Microsoft.EntityFrameworkCore.Query[10100] An exception occurred while iterating over the results of a query for context type 'Infraestructure.Data.AppDbContext'. System.Data....
José Vicente López Delgadillo's user avatar
0 votes
1 answer
32 views

Why does EF Core's DbContext.Update() keep original child entities in DB and at other times doesn't?

My ASP.NET Core Web API app uses SQL Server and I have the following service registered in Microsoft.DependencyInjection as a scoped service: public class UpdateOperation<TEntity, TDto>( ...
ZdenekF's user avatar
0 votes
0 answers
16 views

Inconsistency between Powertools for Lambda (.NET) and EF Core interceptor

For example, I have a EF Core method like this [Tracing(CaptureMode = TracingCaptureMode.Error)] // AWS Powertools for tracking traces public async Task<TEntity> FindAsNoTrackingAsync(...
Batuhan Aydın's user avatar
0 votes
0 answers
37 views

Map JSON column to both string and strongly-typed data with EF Core

An entity: public class Person { // both of these properties should refer to same jsonb column public string ContactsJson { get; } public Contacts Contacts { get; } } public class Contacts { ...
lonix's user avatar
  • 19.6k
0 votes
1 answer
56 views

EF Core FirstOrDefault returns null even if entity exists

I am facing an issue where I cant fetch an entity when using .FirstOrDefaultAsync() with a GUID as the primary key. If I fetch all entries first and then run .FirstOrDefault it works. The entity in ...
rosi97's user avatar
  • 245
0 votes
2 answers
76 views

How can I add multiple conditions in a LINQ Select to return values based on an enum?

I'm working on a LINQ query where I need to select values from a data source based on the value of an enum (ConversationRole). I want to return different user IDs based on whether the ConversationRole ...
Rodrygo's user avatar
  • 13
0 votes
0 answers
56 views

How to exclude records with empty collection in linq query [duplicate]

I have 3 tables in postgres DB (docker postgres:14.1-alpine). public class House { public Guid Id { get; set; } public virtual ICollection<Flat> Flats { get; set; } public ...
Romzes200677's user avatar
0 votes
0 answers
42 views

How can I implement Role Based Access Control in an ASP.NET Core Web API?

I am currently working on improving my Web API skills. I have tried to implement them using the IdentityRole class as well as the Identity User but I don't seem to get the hang of it. I am honestly ...
yzkael's user avatar
  • 125
0 votes
1 answer
35 views

Can I insert ID 0 in MySQL with EF Core HasData?

I'm writing a server for a client that I do not control. I'm using HasData to seed the database with static information that the client refers to by ID. The client uses 1-based numbering for almost ...
Kevin Krumwiede's user avatar
0 votes
0 answers
42 views

change made by _context.SaveChangesAsync written to DB, but on next page, changes are not visible until refresh [closed]

I work on a .NET 6 project based on Blazor and EF Core, which saves a lot of work for me. However, I face a problem: the app has many pages. On the first page, the central service (containing all the ...
tzs's user avatar
  • 1
1 vote
1 answer
36 views

Relation 'Logs' Does note exist (EF Core / PostgreSQL Migration)

Stumped about what's going on here. My LogEntity appears to be implemented no differently than my TenantEntity, and they have the same implementation in my ApplicationDBContext. I am doing a code-...
Chris Phillips's user avatar
1 vote
1 answer
66 views

Include function does not work in EF Core when I inject the generic repository

I implemented this pattern so many times before, I created a context, after that I created a generic repository, like this: public class GenericRepository<T> : IGenericRepository<T> where ...
gokaydinc's user avatar
0 votes
1 answer
40 views

Checking for presence in database and then adding element in Entity Framework causes unique PK error

I have the following code: foreach (var species in list.Species.ToList()) { if (context.Species.FirstOrDefault(x => x.PK_Species == species.PK_Species) == null) { context.Species....
done_merson's user avatar
  • 2,998
0 votes
0 answers
38 views

Entity Framework Core can't find main web project when we set it to run on 32-bit

I have been helping update an old DLL into a REST API. The old DLL had a plethora of references to other DLL's, including one we need that was written in Visual Basic. This DLL also needs to run in 32-...
Chase C's user avatar
  • 86
2 votes
1 answer
75 views

After update to .NET 9: Services for database providers 'SqlServer', 'InMemory' have been registered in the service provider

Upgraded from .NET 8 to 9 and I now get an error in my integration tests: System.InvalidOperationException Services for database providers 'Microsoft.EntityFrameworkCore.SqlServer', 'Microsoft....
Victorio Berra's user avatar
0 votes
0 answers
25 views

GOD Methods or reusing small? [closed]

public class Book { [Key] public int BookId { get; set; } public string Title { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; public string ...
Aleksandro's user avatar
0 votes
1 answer
48 views

Entity framework navigation properties remain null until saving to database

Say I have a basic example of a data tree to save in the database: class TreeModel { int id; virtual Collection ParentNodes; } class ParentNode { int id; virtual Collection TreeModel; ...
Jeroen3's user avatar
  • 935
1 vote
0 answers
27 views

EF Core finding attribute via convention that I don't want it to

I have a class library representing my EF Core 9 database. That library includes a NuGet package of attributes that are set on the model. It's used to configure the generation of PUML files at ...
Gargoyle's user avatar
  • 10.2k
0 votes
0 answers
16 views

EF Core with XUnit "The requested operation cannot be completed because the connection has been broken."

When I run multiple unit tests that use the same API, I am randomly getting this error: The requested operation cannot be completed because the connection has been broken. Here are the exception ...
Muhammad Nasir's user avatar
1 vote
1 answer
60 views

EF Bulk Extensions is really slow for me, but why?

I have a C# console app on .NET 6.0, using EF Core 6.0.35. I am making an API call to get data (from Geotab) that I filter, transform and insert into my DB. Each insert is 1000 to 2000 records. My ...
Adam Hey's user avatar
  • 1,680
0 votes
0 answers
21 views

Cannot Use Multiple Context Instances Error in ABP Framework with CommonDbContext Configuration

I'm working using ABP framework and Entity Framework and I have a simple query like this: // Ensure everything uses the same DbContext (CommonDbContext) var organizations = await ...
Jesus's user avatar
  • 475
0 votes
1 answer
35 views

How to avoid materializing a query prematurely in Entity Framework Core

I am working with the ABP Framework using C# and Entity Framework Core, and I have the following query: public async Task<ListResultDto<GetLinkedOrganizationsDto>> ...
Jesus's user avatar
  • 475
0 votes
2 answers
85 views

EF Core throws a tracking exception when updating entities using AutoMapper

I'm using EF Core against a SQL Server database in a Blazor web app (on .NET 9) with Identity, and I am using AutoMapper to convert between the database entities and the DTOs that get sent out of and ...
Avrohom Yisroel's user avatar
1 vote
0 answers
53 views

EF Core SaveChanges error after explicit transaction

I have a code, which tries to do a certain first set of operations inside an explicit transaction, and then the rest of operations just normally. The transaction goes okay, and gets disposed. Then ...
RifloSnake's user avatar
0 votes
0 answers
33 views

EF Core inherited overriding property not saved with the value given to property

I have a VoucherDefinition class and 4 types derive from that, named: PublicStaticVoucherDefinition PublicRandomVoucherDefinition DedicatedStaticVoucherDefinition DedicatedRandomVoucherDefinition ...
Shahryar Saljoughi's user avatar
-1 votes
0 answers
48 views

I get an error like that "Format of the initialization string does not conform to specification starting at index 0."

I'm trying to write my first API to connect to SQL Server. I have been following all the steps from a tutorial, but I only obtain this error. I have heard this error is because the wrong connection ...
formula's user avatar
0 votes
0 answers
33 views

EF Core Add Migration Error: Duplicate Seed Entity for 'AdditionalProductSubType'

I am encountering an issue when running the Add-Migration command in my EF Core project. The command fails with the following error: System.AggregateException: One or more errors occurred. (The seed ...
A.A.T's user avatar
  • 1
0 votes
0 answers
23 views

GroupBy problem in .NET 3.1 .First()' could not be translated. Either rewrite the query in a form that can be translated,

Models look like this, I made them shorter for explanation public partial class Child : Entity<int>, IAggregateRoot { public Lrp Lrp { get; set; } public int LrpId { get; set; } ...
DastanNasirdinov's user avatar
0 votes
2 answers
74 views

Blazor Quickgrid - how to add a row counter when using Virtualise

Using Blazors Quickgrid. I would like to show a row number for the items. They are 'ApplicationUser' Items. (The id is a guid) It looks like this: <div class="grid" tabindex="-1">...
Brett JB's user avatar
  • 766
0 votes
1 answer
24 views

Dapper logging when using connection from EF Core DbContext

I have a legacy code that is using dapper's QueryAsync() on DbContext's dbconnection: var connection = _context.GetConnection(); await connection.QueryAsync<Guid>(query, parameters); How do I ...
Liero's user avatar
  • 27.2k
0 votes
1 answer
335 views

What are the implications of suppressing EF Core's PendingModelChangesWarning?

I'm working on an ASP.NET Core Web API using Entity Framework Core. As I tried to update my database I get this error: An error was generated for warning 'Microsoft.EntityFrameworkCore.Migrations....
yzkael's user avatar
  • 125
0 votes
0 answers
27 views

Entity Framework Core : nullable FK update child issue

Some question has not group so I set FK as a optional field. When I am trying to update group, I get an error. If GroupId is required, then there is no problem. public class Question { [Key] ...
Tom Zhao's user avatar
-1 votes
0 answers
45 views

Entity Framework Core C# recursive load of the parent child relationship lazy loading [duplicate]

I have a table in my database with a parentID column referencing the same table's ID key column. Each entry in that table can have a parent - record from the same table and list of children - also ...
Semen Shekhovtsov's user avatar
0 votes
0 answers
34 views

Missing field after a document Insert/Update in mongodb through C#

I have a migration script that tries to insert data into mongodb. I build the document object and insert it into a collection. The main document object has a bson element that has a recursive/nested ...
lsp's user avatar
  • 161
0 votes
0 answers
46 views

ASP.NET Core Identity Framework + EF Core Postgres + snake case table names

I would like to configure ASP.NET Core Identity Framework + EF Core on Postgres with lowercase snake_case table names. As it currently stands my IdentityDbContext looks like this: using Microsoft....
Brian Mikinski's user avatar

1
2 3 4 5
465