Questions tagged [entity-framework-core]

Entity Framework Core (EF Core) is an open source, extensible, lightweight and cross-platform ORM developed by Microsoft, targeting .NET 6. Please add a version-specific [ef-core-x] tag, when applicable. Do NOT use this tag for Entity Framework questions; use [entity-framework] instead. Entity Framework is a different, and much older, product.

Filter by
Sorted by
Tagged with
0 votes
1 answer
29 views

Why does Entity Framework Core require "top 200" for ContainsTable() order by?

In SSMS the following query works fine, returning the expected 1 row: SELECT * FROM CONTAINSTABLE(AppUsers, *, 'hick', 200) AS t INNER JOIN AppUsers u ON u.Id = t.[KEY] ORDER BY t.[RANK] DESC But ...
David Thielen's user avatar
1 vote
0 answers
46 views

Is it possible to use navigation properties with no foreign key constraint?

I have a system in place that has a collection of Func<IQueryable<T>, IOrderedQueryable<T>> items that specify how data should be sorted. So, for example, on entry might look ...
Jonathan Wood's user avatar
0 votes
1 answer
33 views

EF Core 7 (Entity Framework) Multiple relationships to same entity

I have 2 classes. A Company Class and an Item class. An Item has 2 Companies assigned to it in different roles. A company has a list of all items it's been assigned to, which is used to determine what ...
Chuck Breedlove's user avatar
0 votes
0 answers
13 views

Is there an EF.Functions.ContainsTable() equivalent?

There's an EF.Functions.Contains() and EF.Functions.FreeText(). But I can't find a ContainsTable() or FreeTextTable(). Is the only way to do those to use FromSqlInterpolated()? And if so, is this the ...
David Thielen's user avatar
0 votes
2 answers
37 views

Blazor Server EF Core: Related data (one-to-many relationship) does not save

SalesItemNecessities are created when adding an new Activity. However, the SalesItemNecessities do not get updated when updating the parent Activity. Anyone any tips? I have two models: public class ...
Jeremy's user avatar
  • 62
0 votes
0 answers
42 views

EF Core 7 Data is Null. This method or property cannot be called on Null values

I have .net 7 web api and EF Core 7.0.11 and I'am trying to get operator object from DB by login column (nvarchar(100), nullable). List<Operator> op = await _dbContext.Operator.Where(w => w....
blane's user avatar
  • 159
1 vote
2 answers
59 views

Entity Framework DbContext instance being disposed when two different instances used as Task

I'm trying to run two queries in parallel, which then get loaded into a view. I'm doing something like this: Task<IEnumerable<MyClass>> someData; Task<IEnumerable<MyOtherClass>>...
WSC's user avatar
  • 913
0 votes
0 answers
30 views

Json column stored foreign key for table EF core

Json stores foreign keys for other tables. How to connect it to user and profession models after deserialization? Is it possible to deploy json in this way and immediately include it to the model? ...
HichDX's user avatar
  • 1
-1 votes
0 answers
51 views

why the compiler stops running when upload picture [closed]

I want to upload the image from client side to server side but the compiler stops working when I upload the image in ASP.NET CORE MVC. I try input data for new product and I want to upload a picture ...
S_ENG Osama's user avatar
0 votes
1 answer
15 views

EF + Mysql 8.1 suddenly System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.UInt64'

I am suddenly getting from a simple EF query the error: System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.UInt64'. at MySqlConnector.Core.Row.GetUInt64(...
Sam's user avatar
  • 801
1 vote
0 answers
41 views

EF Core fluent config "DbUpdateConcurrencyException"

There are a few questions out there about the following exception, but I can't find any that match my scenario. Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException : The database operation was ...
Adam Hey's user avatar
  • 1,532
0 votes
1 answer
44 views

Map multiple C# entities to a single database table in EF Core 6

I'm trying to figure out how to map multiple C# entities - Opportunity (all attributes) & OpportunitySummary (subset of attributes) - to a single database table Opportunity in EF Core 6. The ...
WHowing's user avatar
4 votes
1 answer
50 views

Search a table using a list of strings in EF Core 8 preview (where in clause)

** UPDATE ** So I took the suggestion below and set the compatibility level to 150 (SQL Server 2019) as it was set at 100 and reran the code and it resulted with the same issue. Next step is to set ...
Mike's user avatar
  • 3,236
1 vote
1 answer
22 views

Unable to cast object of type 'System.Linq.EmptyPartition1[Model]' to type 'System.Collections.Generic.List1[Model]' using EFCore.BulkExtensions

I'm using EFCore 7.0 and EFCoreBulkExtensions 7.1.2 When I'm trying to execute a _context.BulkUpdate(list, bulkConfig); It thows an <System.InvalidCastException>: Unable to cast object of type '...
Luis Santos's user avatar
1 vote
1 answer
60 views

Multiple ON conditions in JOIN using Fluent API

A little bit of preface: I am working in EF Core 6 and was trying to create an SQL query using the Fluent API. The raw SQL query that I am trying to achieve is: SELECT * FROM [table] AS [t] LEFT JOIN [...
TheCaeserSalad's user avatar
0 votes
1 answer
40 views

A key cannot be configured on 'Foo' because it is a derived type. The key must be configured on the root type 'ApplicationUser'

I got this error on db migratios: A key cannot be configured on 'Foo' because it is a derived type. The key must be configured on the root type 'ApplicationUser'. If you did not intend for '...
Sachihiro's user avatar
  • 1,621
0 votes
0 answers
80 views

How to efficiently Read and Update Thousands of Entities using EF Core [closed]

I'm working on a solution built using .NET Core 7 and EF Core, and I'm facing performance issues with a specific method. This method is responsible for performing a series of actions, and I'd like ...
Alisbha Khan's user avatar
0 votes
0 answers
25 views

Does the "Executed DbCommand" logging statement in .NET EF Core includes latency?

I have a question regarding the "Executed DbCommand" statements output by the Microsoft.Extensions.Logging mechanism in a .NET project utilising EF Core. Namely, does the time logged in this ...
Nikola Vetnić's user avatar
0 votes
0 answers
43 views

Multiple repositories in the service

I have a problem, in my server project there are related entities with a one-to-many relationship, implemented through Entity Framework. Classes: public class University { public int Id { get; set;...
Pavka's user avatar
  • 1
1 vote
1 answer
19 views

Authenticate in ASP.Net Core using API-Token

I am currently using JwtBearer as the authentication scheme, meaning users have to log in using their username and password and receive a token which authenticates them for a while. Now I need to make ...
TaCqz's user avatar
  • 11
0 votes
0 answers
54 views

Ef core tracking behavior

I have the following two code snippets which do a similar thing var camera = await dbContext.VideoCameras .Include(c => c.Users) .FirstOrDefaultAsync(c => c.Id == request....
schgab's user avatar
  • 521
2 votes
3 answers
104 views

What is the proper way of autoincrementing non primary key column?

I have a table which has an integer field which is supposed to be unique and autoincremented. After doing some research I came up with two different approaches: Case A modelBuilder.Entity&...
theuserthatpretendstobesmart's user avatar
0 votes
1 answer
39 views

ASP.NET Core MVC: Passing one parameter from a view to a controller

I have my Regions Index here that passes the regionID for a region through as an asp-route-id that is meant to go to this URL when the link is clicked (which it does): /Countries/Index/{id?} @model ...
softloftmaria's user avatar
-1 votes
1 answer
24 views

How to get the related data from the child table using Entity Framework in ASP.NET Core

Below is my table structure which is related via foreign key constraints CREATE TABLE "EMPLOYER_TYPE" ( "ID" NUMBER(5, 0) GENERATED ALWAYS AS IDENTITY MINVALUE 1 MAXVALUE ...
soorya kumar's user avatar
0 votes
1 answer
41 views

Understanding EF Core SQL query translation

I have questions, regarding EF Core translation, is this query already optimized? SELECT e."EmployeeId", e."PositionId", t."Name" FROM "Employee"...
Vendy's user avatar
  • 19
0 votes
0 answers
56 views

Establishing SSL trust to SQL Server with an AWS Lambda (Linux Client)

I'm trying to connect to a SQL Server 2019 instance from an AWS lambda. I'm using a self-signed certificate for the SQL instance. Our lambda is using Entity Framework Core 7.0.5 in .NET 6 (also tested ...
Erik Farrell's user avatar
0 votes
0 answers
26 views

WebApplicationFactory gets connection string from service appsettings.json not test project appsettings.json

My api project has an appsettings.json with a connection string for "Settings" database My WebApplicationFactory in the test project has an appsettings.json with a connection string for &...
HelloWorld's user avatar
  • 4,681
0 votes
1 answer
21 views

How to add/insert data using EF core code first for reference values?

Let's say we have a table which stores references/foreign keys to several tables. We are to insert record in such table using EF Core code first approach. Here is what I have: _context.AuditLog.Add(...
TechTurtle's user avatar
  • 2,685
0 votes
1 answer
21 views

I am struggling with the model below

I have this model namespace AppCore.Entities; public class ProductQuestion : _BaseEntity { public ulong AppUserId { get; set; } public AppUser? AppUser { get; set; } public ulong? ...
Saeed Noruzi's user avatar
-2 votes
0 answers
76 views

Cannot set value to combo box [closed]

I wanted to set the value of the combobox to the selected value from sales invoice but it does not change the project doesnt have error only the assigned value should change combobox selectedvalue but ...
Junix Chan's user avatar
0 votes
0 answers
32 views

I am constantly facing transient failure on "add-migration" command

I am working on .Net 7 project and I have installed the following libraries for the Code First Approach: Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.tools. Problem: I am ...
Humzamanzur's user avatar
0 votes
1 answer
37 views

Get all is returning entities which has delete state

I am getting all entities (3 items). Removing one of them, but not saving. Then getting all again. It is returning me a deleted entity however state of the entity is deleted. Is it something expected? ...
Dilshod K's user avatar
  • 2,924
0 votes
0 answers
22 views

Entity Framework Core InverseProperty Error: The given key 'System.Nullable`1[System.Int32] ChildId' was not present in the dictionary

When I try to create a migration I get this error: "The given key 'System.Nullable`1[System.Int32] ChildId' was not present in the dictionary." Basically I want to create a relationship for ...
David's user avatar
  • 53
0 votes
1 answer
43 views

EF Core Sqlite one-to-many, adding a new record

I am working on a project that has a relationship near enough to the one in the Microsoft documentation: https://learn.microsoft.com/en-us/ef/core/modeling/relationships public class Blog { public ...
user7704925's user avatar
0 votes
0 answers
47 views

Where multiples conditions EF Core

I have the following problem and that is that when a record does not have the RequestAssignments list it does not bring me the join and it does not bring me that record, I want it to bring me the join ...
ASBEL SANTANA JIMENEZ's user avatar
0 votes
1 answer
35 views

How in T-SQL can I set the next N isAudits to true every X records?

I'm trying to figure out, either using T-SQL or C# / Entity Framework, how I can mark a batch of N records true every X records that get created. So here's an example of what the data would be if N = ...
thetimmer's user avatar
  • 188
-1 votes
0 answers
36 views

Entity Framework Core database-first approach [duplicate]

I used database-first approach to create entity data model & context and performed to crud operation. If a new table (ex: products) has been added to database, please explain how to add the newly ...
jayasri's user avatar
  • 17
0 votes
0 answers
39 views

.NET Core 6, Entity Framework Core, Oracle : an exception occurred while iterating over the results of a query

I am using .NET Core 6 and Oracle.EntityFrameworkCore ( 7.21.11 ) --EDIT Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 this is my setup builder.Services.AddDbContext<DbContextOracle>(...
Subin Adhikari's user avatar
0 votes
0 answers
51 views

EF Core 7 Mapping

I have two tables that look like this. TABLE 1 CREATE TABLE [dbo].[CompanyMap]( [AMLI_COMPANY] TABLE 2 CREATE TABLE [dbo].[Companies]( [CompanyCode] The parent/child relationship should ...
Mark Richardson's user avatar
0 votes
0 answers
56 views

Make reusable expressions for Entity Framework queries

I have a query that looks something like this. var railcars = DbContext.Railcars .Select(r => new { Number = r.RailcarNumber, Quantity = r.InboundQuantity - ...
Jonathan Wood's user avatar
1 vote
2 answers
55 views

The instance of entity type cannot be tracked because another instance with the same key value for {'Id'} is already being tracked

I'm trying to update a record in the database but I get an error I can't solve. public async Task<bool> AddUpdateAsync(Activity objActivity) { try { using (var _db = _factory....
Jeremy's user avatar
  • 62
0 votes
1 answer
41 views

Access to the path 'Microsoft.EntityFrameworkCore.Analyzers.dll' is denied

When im trying to add new NuGet Packages I get this error: System.UnauthorizedAccessException: Access to the path 'Microsoft.EntityFrameworkCore.Analyzers.dll' is denied. Tried to restore but same ...
IseySkrr's user avatar
0 votes
0 answers
36 views

EF, postgres, unrecognized winsock error 10054

I am writing a .NET app that uses Entity Framework to write data to a Postgres v12 database. The app itself watches the filesystem and writes data to the database every time it sees changes. The data ...
suriel's user avatar
  • 313
-1 votes
1 answer
43 views

I have tried to use Update-Database but get an error - how to fix this? [closed]

System.InvalidOperationException: The ConnectionString property has not been initialized. appsetting.json "ConnectionsString": { "GShopConnectionString": "Server=...
Ali Garivani's user avatar
0 votes
0 answers
48 views

ASP.NET Core MVC & Entity Framework Core: Fluent API relationship configuration wrong

I believe that I have my relationship between the Relationship and RelationshipType models wrong. Basically I want to create a relationship for a contact with another contact, e.g. Contact1 has a ...
David's user avatar
  • 53
-2 votes
0 answers
16 views

Missing last couple of record when doing bulk insert [closed]

I have a method as below which loops on a file and read data from each file. I want to do bulk insert 10 records at a time. I have 14 records in file but only 10 records are inserted and remaining ...
I Love Stackoverflow's user avatar
-4 votes
0 answers
75 views

What is the best way to store and work with order statuses? [closed]

I'm designing a db schema for food delivering service. Order sequentially can been in one of 7 statuses: public enum OrderStatus { Created, Confirmed, Preparing, Prepared, Shipped, ...
HostMan's user avatar
0 votes
1 answer
27 views

In One To Many Relationship, How Do I Return JUST The Many entities Given A Specific Entity On The One Side

I have two two tables A and B that have a one to many relationship. I want to return all the B records (as a list) associated with the most recent A record that has a specific UserId. I have the ...
jmath412's user avatar
  • 421
0 votes
0 answers
25 views

Discriminator problem on Views inherit from table

I use EF Core in my project and have a base class Person. In addition to the Person, I have multiple views inherited from the base class because I want the fields and relationships of the base class. ...
bealtis's user avatar
  • 23
0 votes
0 answers
31 views

EF Core Query One To One Self Relation

In EF Core I want to manage a collection of Parameters (Entity Parameter). A Parameter is basically a named Value and can belong to a Recipe or can be global (no Recipe). Therefore the Reference from ...
AndiR's user avatar
  • 181

1
2 3 4 5
428