8,516 questions
0
votes
1
answer
140
views
How do I create connection string with App Registration/Service Principal for a Web API using EF Core app with SQL Server using Microsoft Entra MFA
I have a generic ASP.NET Core Web API that uses EF Core to connect to a SQL Server instance that uses Microsoft Entra MFA account.
The connectivity prompt for the SQL Server looks like this:
I have ...
0
votes
1
answer
106
views
Trying to populate very similar relations through same property
I am trying to define two classes with the same collection-relation, through the same key on a third class, preferably using EF 6 code annotations.
I have three tables;
Current is a quick reference. ...
0
votes
2
answers
66
views
How to create two table from one class by EF Core
I have a class for users :
public class users
{
public int UserId { get; set; }
public string UserName { get; set; }
// ....
}
I want to create a table called users. I write this line in ...
0
votes
0
answers
65
views
SqlException: Invalid column name (EF DBFirst to CodeFirst)
I know there are a ton of QAs on this topic but none of the answers I've looked at have helped me. I'm sure it's something simple.
I am in the process of moving from database-first to code-first using ...
0
votes
0
answers
28
views
Separate navigation properties for distinct subtypes in TPH hierarchy
I have an Entity Framework 6 (v6.5.1) code-first model like this (type names have been changed to anonymise the code):
public abstract class Point
{
public long ID { get; set; }
public long ...
0
votes
1
answer
78
views
How do I display the Sum records of a child property in a field in the parent model?
How do I display the Sum records of a child property in a field in the parent model?
for example
Order Model:
public class Order
{
[Key]
public int Id { get; set; }
public string Title ...
1
vote
1
answer
200
views
DbUpdateConcurrencyException in EF Core during SaveChangesAsync
I'm working with Entity Framework Core and encountering the following error:
Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException
Attempted to update or delete an entity that does not exist in ...
0
votes
1
answer
56
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 ...
0
votes
1
answer
53
views
How can I ignore an FK defined in a base type when using TPT in EF Core
I have an Entity Framework Core model defined as follows:
class User
{
public int ID;
public ICollection<Foo> OwnedFoos;
}
[PrimaryKey(nameof(ID), nameof(OwnerID))]
class Foo
{
...
0
votes
0
answers
60
views
EF Core does not allow Cascade Delete on 2 foreign keys, but Blazor sample web app does this just fine
I have seen countless posts advising that EF Core with SQL Server blocks multiple foreign keys which have "OnDelete Cascade" (due to cycles and multiple delete paths). However I see in the ...
1
vote
1
answer
176
views
Entity Framework Core 8 : many-to-many relationships issue when updating the data
I'm building an Entity Framework Core web project using code first migrations and when I update the data via update method, I get the following error message:
Violation of PRIMARY KEY constraint '...
0
votes
0
answers
23
views
Getting error while using Add-Migration Initial
I have been trying to use code first approach to create a database via already written models and context class. Below is my context class for reference.
using BankLibrary.Models;
using Microsoft....
0
votes
1
answer
216
views
How to create migrations with multiple projects architecture in ASP.NET Core 8
I have created two projects in ASP.NET Core 8:
1. Web API project which contains
Connection string in appsettings.json
DbContext registration along with connection string in Program.cs file
2. Class ...
0
votes
1
answer
1k
views
Storing an owned entity as JSON, and managing updates to the object graph
I'm using EF Core (8.x) and Posgresql for storing some data. Specifically, I have an entity type which has a (navigation) property holding an entire object graph, that I have specified in ...
0
votes
1
answer
66
views
EF Core - Need to reference the many-to-many join table in code-first application
I have a mapping application that will display pins on a map that represent Features at Member addresses (e.g. a Member lives at lat/long 'X' and is associated to Feature 'Y'). Members can be ...
0
votes
1
answer
131
views
using DbContext in Task does not work properly and only works once and crash if used twice
i am working on a Winui/c# app with EF core and sqlite db.
i am searching in a db with multiple tables every tables contains 9M records (9,000,000).
for this heavy search i used Task.Run and async/...
0
votes
1
answer
94
views
.NET Core / Blazor model attribute that doesn't get persisted to database
I have a model in my Blazor app that I want to create a "transitory" attribute for. This attribute is used internally in the app, but I do not want to persist it to the database.
However, ...
1
vote
1
answer
38
views
How to set foreign key null by updating parent entity in EF Core?
I have two entities with this structure:
public abstract class BaseEntity
{
public BaseEntity()
{
//Validate();
}
public Guid Id { get; set; } = Guid.NewGuid();
public ...
0
votes
0
answers
129
views
Translation of 'EF.Property<Guid?>(f.ISBN, "Id")' failed on a string functional key field
Assume a class like this:
public class Book
{
[Key]
public Guid Id { get; set; }
public string ISBN { get; set; } = default!;
public string Name { get; set; } = default!;
public ...
2
votes
1
answer
499
views
Avoid double quotes when querying Oracle tables created by EF Core 8 Code First
Background
I have a table model like this:
public class Book
{
[Key]
public Guid Id { get; set; }
public string Name { get; set; } = default!;
public string Author { get; set; } = ...
0
votes
1
answer
619
views
EF Core 8 Code First Migration Missing Default Values
I am working on a .NET 7 project with EF Core 8 and attempting to use code first migrations with Microsoft SQL Server, but for some reason I can't get any default values to generate in the migrations.
...
1
vote
1
answer
2k
views
Unable to create a 'DbContext' of type ''. The exception 'Object reference not set to an instance of an object.'
I am trying to create migration using Add-Migration InitialMigrations in my Asp.net Core 8 Web API project, but I am getting the following error:
Unable to create a 'DbContext' of type 'AMSContext'. ...
0
votes
0
answers
56
views
How to remove PasswordHash Autogeneration when seeding Identity NET CORE
I'm seeding the User identity table using EF core configurations, this is my method.
public void Configure(EntityTypeBuilder<IdentityUser> builder)
{
var hasher = new PasswordHasher<...
0
votes
1
answer
35
views
Is there a better way to approach this database tree structure using Entity Framework 7.0 code first
I am developing a database using c# with Entity Framework 7.0 Code First. I have come across a scenario that's a little tricky for me. Consider the following entity diagram.
A Store has many Pods
A ...
1
vote
2
answers
2k
views
"The property or navigation cannot be added type because a property or navigation with the same name already exists" when adding migration
I am working on a .NET 8 project using C# and Entity Framework Core. I am trying to add a navigation property in my data model to create a connection in the tables. I followed the documentation from ...
0
votes
1
answer
99
views
How to make a new database using Code First in WinForms
I want to make a MSSQL using code-first approach.
I have defined two models - Product and Category and then defined the DbContext as you can see below:
public class ApplicationDbContext : DbContext
{
...
0
votes
0
answers
169
views
HasComputedColumnSql() method not working as Expected
I have configured the updatedAt property as shown below. I expected that the updatedAt value of the corresponding row alone will change when inserting or updating. But when tried this it is updating ...
0
votes
0
answers
59
views
Different tool to generate codefirst migration. Time to clean up and refactor
I've inherited a non-complete clean solution from the point of view of CodeFist on a .NET 7 project.
The scenario is the following:
I had an old part of the Codebase that used EF Code first migration
...
0
votes
1
answer
358
views
How can I access Entity Type information in EF Core with code first?
In Entity Framework Core, how can I access the Entity Type data (the entity names, regular properties, navigation properties, etc.) when using code-first? When using database-first, I can use ...
0
votes
1
answer
58
views
Error In create constraint or index on asp.net
I have Three Table ApplicationUser, Posts, Comments
there is a one to many between users and Posts
there is a one to many between Posts and Comments
these Relations Has CasCade Delete and working ...
0
votes
1
answer
498
views
Introducing foreign key constraint may cause cycles or multiple cascade paths - How do I specify "ON DELETE NO ACTION"?
I have 6 entities in total but my issue is with these following 3:
Departement, Filier and Etudiant.
The Departement entity contains many Filiere and many Etudiant entities, while Filiere and Etudiant ...
2
votes
2
answers
2k
views
Entity Framework Core - One-to-one relationships not creating foreign key
I'm in .net8 ef core with postgres database and code first approach.
I have these two class:
public class Soggetto
{
public long Id { get; set; }
public virtual Azienda ...
0
votes
1
answer
54
views
Entity Framework code-first, Null entries being written to database
Refer to my code example below where I'm trying to implement a code-first connection to a SQLite database. I am working in .NET 4.8 (not Core). All the column names and database table names are ...
0
votes
0
answers
75
views
.NET EF Core Sort by child collection property
I have a patient class which has navigation property PatientGroupMemberships, and PatientGroupMembership had PatientGroup property, and PatientGroup has property Name.
I want to sort by Patient's ...
2
votes
0
answers
121
views
Dependency loop despite entities configuration in Entity Framework. Include vs Join
I have a question about Entity Framework. I use the Code First approach. Let's say I have several classes representing a table in a database. I use navigational properties and in some places the IDE ...
0
votes
0
answers
219
views
Saving parent and children into separate tables with EF Core
My app has an abstract base/parent class (Contact), and concrete child classes (Phone, Email) inheriting from the base, and other classes referenced from the base - I left Person and Notes for the ...
0
votes
0
answers
72
views
How to initiate domain services in DDD and Entity Framework?
I have a Domain model below that needs two domain services to check the database state and generate the date time now for the sake of testability:
public class Person
{
public string Name { get; ...
0
votes
0
answers
28
views
Insert entity with navigational properties
I have an entity business owner given below. It is recursive entity with ParentBusinessOwner property.
public class BusinessOwner : ISystemOperated, ICachable
{
[Key]
public int ...
0
votes
1
answer
108
views
Entity Framework returns null value of associated tables when using stored procedure
I am using code-first approach in EF, I have created a stored procedure to select, and when I run it, I get the value from User table but the FK attributes are null.
This is my stored procedure:
ALTER ...
0
votes
1
answer
243
views
multiple one-to-one relations using composite primary keys
I am trying an experiment to switch from a one-to-many that will always have 2 in the list, and have 2x one-to-one relations using composite keys.
Modeled classes:
public class Game
{
[Key]
...
0
votes
0
answers
53
views
EF 6.4.4 Multiplicity constraint violated. The role 'SaleDetail_Ledger_Target' of the relationship 'BLL.SaleDetail_Ledger' has multiplicity 1 or 0..1
I am trying to update an entity named SaleLedger with some relationships in it. But while calling Context.SaveChanges() it throws an exception
I am using EF 6.4.4 and SQL Server database
My Entity is
...
0
votes
0
answers
58
views
Can't convert from model to path.model C# Entity Framework
I'm trying to do my first API with ASP.NET Core 6 and Entity Framework Core.
Basically I have a model class:
namespace SistemaDeTarefas.Models
{
public class UsuarioModel
{
public int ...
0
votes
1
answer
35
views
Adding the version system and table history to the table in the code first method
I need to use the system version property and the table history of the SQL in the code-first method, so that one, by using a token, when a record was changed between selection and editing, it gives an ...
0
votes
1
answer
57
views
Deleting an UnAttached entry from dbContext cause exception when using GraphDiff
I'm using GraphDiff library in my c# project to update a disconnected graph. My Document entity has a one-to-many relationship with DocumentRelationShip entity as ToDocumentRelationship navigation ...
12
votes
2
answers
9k
views
After upgrading to Dotnet - Database Compatibility Version - Not EFCore UseCompatibilityLevel, SqlException: Incorrect syntax near '$' [duplicate]
I have an ASP.NET Core project which uses code-first in EF Core.
After upgrading from .NET 7 to .NET 8 and also EF Core packages I'm faced with an error
SqlException: Incorrect syntax near '$'.
This ...
1
vote
2
answers
100
views
The entity type 'List<Workout>' requires a primary key to be defined
My problem is I get this error
The entity type 'List' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on ...
0
votes
1
answer
207
views
How to disable automatic migrations and create new columns/tables all by myself in code-first enviroment?
First of all it needs to be clear that I never worked on a project that uses code first, and I inherited this project from another developer.
Right now I am trying to reproduce the error to post here ...
1
vote
1
answer
168
views
EF core Exceptions not getting Caught in ExceptionFilters
Almost all exceptions are getting caught except the exception from EF core . The exception filter is catching any error . but not errors from entity framework. If you need any other info like efcore ...
0
votes
0
answers
50
views
EF Core, code first approach, one table with multiple foreign keys to same table using SQL Server
I have a requirements where we are supposed to store all the key-value in one table. For example, status of application, status of user requests, status of incident etc. We don't want to create ...
0
votes
1
answer
882
views
Use a DbContext inside a Migration
I want to use DbContext variable inside the Migration Up method.
I explain better my problem:
I have one migration done in this way
class Circle {
public int Id {get; set;}
public int Radius {...