835 questions
1
vote
0
answers
123
views
Why Entity Framework Core uses class name instead of table name while creating name for foreign key constraint
I have these model classes (deleted not related parts):
internal class RelationTypeModel
{
public Guid Id { get; init; }
public required string Name { get; init; }
public class ...
0
votes
1
answer
78
views
How to prevent generating shadow property for one to many relation when there can be more than one foreign key used
I have this model class:
internal abstract class GraphNodeModel
{
public Guid Id { get; }
public Guid TypeId { get; }
public virtual GraphNodeTypeModel? Type { get; }
public List<...
1
vote
1
answer
69
views
How to set up a cyclic connection in EF Core?
I have works, users and likes. A like is a connection between a user and a work. The work was created by a user.
I would like to have tables like this:
public class DbUser
{
public Guid Id { get; ...
0
votes
0
answers
62
views
Renaming a SQL Server table using Fluent API in .NET Core
I am working on a console application in order to practice my skills. I've connected to my SQL Server database, created the tables and seeded the data using code first approach.
Now I am trying to use ...
0
votes
1
answer
66
views
EF Core Fluent API One-To-Many Mapping using mapping table [child table]
I'm trying to create a one-to-many mapping using EF Core Fluent API.
I have these 3 tables:
User
Role
User Role Mapping Table
These C# classes represent these tables:
public class User
{
public ...
0
votes
1
answer
79
views
EF Core Fluent API: One-to-One relationship with 2 different syntax, only one is working
A one-to-one relationship is defined between 2 entities in 2 different ways, but only the one using generic methods is working. The configurations are done on the DomainVerification entity.
Given the ...
0
votes
1
answer
91
views
Create one-to-one relation without adding reference in one of the tables
I have 2 tables Company (Id uniqueidentifier, ...) and Address (Id int, ...) and representative entities Company and Address.
They should have a one-to-one relationship. As I don't want to have any ...
0
votes
0
answers
84
views
Overriding identity tables properties / columns in EF Core 8 has no effect
I'm overriding the IdentityRole / IdentityClaim, etc.
However, I've noticed that some of these fields has no effect either in Fluent API or via attributes.
Class that overrides IdentityRole<Guid>...
2
votes
1
answer
352
views
Many-to-many relationship defined in EF Core Fluent API
This might be a duplicate but sincerely I have spent sleepless nights trying to figure out how to implement this relationship. Basically, a bank customer can have many accounts that they are primary ...
0
votes
0
answers
54
views
EF Core FluentAPI Multiple Field Issue
I have inherited some code which is now causing an issue w. The code looks similar to the following (albeit redacted).
public class ObjectX {
public Guid Id { get; set; }
public List<ObjectY&...
0
votes
1
answer
273
views
Compute field on update and Insert using Fluent API
I am trying to configure a field in model which is to be modified with insert and update.
I tried multiple things but still could find the correct configuration for my requirement.
Example :
public ...
0
votes
1
answer
36
views
Is it possible to configure relationship between 2 classes just using ids instead of navigational properties?
I have 2 classes and I want to avoid using navigational properties.
So instead of:
public class A
{
public int Id { get; private set; }
public B B { get; private set; }
}
public class B
{
...
1
vote
1
answer
640
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 [...
0
votes
1
answer
149
views
EF Core Property/Column Sharing
Original Question
I have the following entity I’m trying to get to work with EF Core/NET7, where two properties map to the same column. This way either property could be used in various interfaces ...
2
votes
1
answer
290
views
How to map properties that belongs to fields of the join table of a many to many relationship?
I have a table bills and a table documents. A bill can be related with many documents and a document can be related with many bills. A many to many relationship.
Also, in the join table, a have a ...
1
vote
1
answer
500
views
KeyAttribute attribute does not work when setting primary key
The Entity Framework Core version is 7.0.10. While getting data from database, it throws out no primary key exception even I have already set it up in model class.
The entity type 'Order' requires a ...
1
vote
0
answers
149
views
EF 6, .NET 4.8 : resulting query doesn't seem to use StringLength
I've seen similar questions and have tried applying the answers, but to no avail, so I wanted to ask my question with more context of what I've tried.
My property looks like this:
[Column("colnm&...
1
vote
1
answer
274
views
Several foreign keys in same table EF Core 7
I have two entities CodeMaster and Employee. In Employee, I have more foreign key optional properties to navigate to the CodeMaster entity. When I insert data into Employee, I get this error:
Inner ...
0
votes
1
answer
308
views
"Ghost" shadow-key in EF Core fluent api
I have this setup (roughly, I've edited out the irrelevant code for readability).
public class LevelSection
{
public Guid Id { get; set; }
public Guid UserDataId { get; set; }
}
and then
...
0
votes
0
answers
57
views
EF Core 6.0 One-To-Many one-way link with middle table using another table primary key
I am having trouble trying to link an object to a list of Addresses using a middle table that is uses a different table's primary key with the primary key for Address. I want a one-to-many one-way ...
2
votes
0
answers
21
views
When I set two collections of the same entity entituy core tries to use the default column name
First I will expose the code that reproduces the problem. Then I will explain the problem.
I have two entities, Employee and ContactForm (address, email, telephone...):
public class Employee
{
...
1
vote
0
answers
99
views
How to configure composite key in EF Core fluent API when the composite key is composed by 2 Value Object
I have these 3 Value Object (LanguageId, AttributeSetId and AttributeSetTranslationId
public record LanguageId(string LangCode);
public record AttributeSetId(Guid Value);
public record ...
0
votes
0
answers
83
views
DbContext's DbSet<> member throws InvalidCastException upon DbSet.ToArray(), trying to cast to another declared entity type
I'm using EntityFrameworkCore 7.0 in conjunction with Pomelo.EntityFrameworkCore.MySql to build a Code-First app relying on MySQL.
I'm using the Fluent Api and IEntityTypeConfiguration<> ...
0
votes
1
answer
628
views
Entity Framework Core; how to use a many-to-many table's composite key as a foreign key?
This is my first question on the website, so if something seems off or the syntax isn't quite right, please let me know!
The schema below allows a player to join a profile using the many-to-many table ...
0
votes
3
answers
127
views
How to create relation between one entity and others entities types using child id and child type in C# .net core EF?
I want to create a direct relation between the Task entity and the child entities, to get with the task the corresponding child and when I get the child to get the corresponding task.
I have an entity ...
0
votes
1
answer
148
views
Works incompelete Fluent API in migration
I created a model called ProductCategory (image #1) and configured this class using the Fluent API method (image #2), but unfortunately when I create Migration, all the configurations including the ...
0
votes
1
answer
373
views
How can I list objects from abstract classes that include all specific subfields in EF Core?
I have been with this issue for some time now, and I have not seen a solution in either Microsoft's docs or on StackOverflow.
The issue: I have an abstract class, Workout:
public abstract class ...
0
votes
0
answers
154
views
What's the right way to configure a one-to-one relationship when using Entity Framework Core migrations so that foreign keys are added to both tables?
Let's say I have two entities/model class
AccountModel:
public class AccountModel
{
[Key]
public int AccountSk { get; set; }
[ForeignKey("Region")]
...
1
vote
1
answer
267
views
Entity Framework, Fluent API relationships - many-to-one-or-zero
I am trying to setup a specific relationship using FluentAPI on 2 entities. See details below
public abstract class Entity
{
[Key]
public int Id { get; set; }
}
public class Inventory: Entity
...
1
vote
0
answers
705
views
Why is EF Core not using ON DELETE SET NULL when applying a migration?
I am using Entity Framework Core 6.0 and SQL Server.
I am trying to update a relational database to reflect this diagram:
ER Diagram
where a single red line over a relationship represents ON DELETE ...
1
vote
1
answer
1k
views
Entity Framework fluent one-to-one - property/navigation already exists
I have two entities, Movie and UserRating. I want to be able to specify table names and column names myself. UserRating shall have a foreign key to Movie in the database, but I'd like both entities in ...
1
vote
1
answer
190
views
Entity Framework Fluent API - Map Property to Specific Table
I would like to create internal mapping of navigation property to specific table using EF's fluent API.
Meaning - Same type is mapped to different tables according to parent type
(see code below)
...
2
votes
2
answers
3k
views
How do I create a One-to-One mapping without using a foreign key constraint?
Problem - I need to create some type of mapping between 2 entities with property "SourceTransactionId", where either entity can be added to the db first, before the other, but still be able ...
0
votes
1
answer
81
views
When I take information from a database object, I get null, such as Car.Color = null
I had mistake, but does not understand where. When I`m add to my database object they saved correct, unfortunately not equals my image, maybe it`s my mistake. I need hint to where look. For the sake ...
2
votes
0
answers
58
views
Configure Many-To-Many EF Relationship Between Separate Aggregates Without Using Navigation Lists
I have two entities from separate aggregate groups that have a many-to-many relationship:
public class ClientNotificationMethod
{
public int ID { get; private set; }
private ...
1
vote
1
answer
269
views
How to share Entity Framework Fluent API mapping with Dapper?
There are two ORM in my .NET Core 6.0 project, Entity Framework and Dapper. I would like to share the Fluent API with Dapper. Is there any way to do this? The main goal is to centralize the mapping of ...
1
vote
1
answer
529
views
Does fluent API IsRequired() does exactly the same as [Required] attribute over the property?
If I put [Required] attribue over a property in a model then the <input> helper tag will throw out a validation error if no value is provided, but also it will be affecting database structure.
...
1
vote
1
answer
2k
views
How do you add a Unique case insensitive Index to a PostgresSQL table using EF Fluent API
I have recently been using PostgreSQL rather than SQL, so finding a lot of little nuances between the two.
I want to be able to make a string value unique in a table, so using the EF code first fluent ...
0
votes
1
answer
559
views
Entities in '' participate in the '' relationship. 0 related '' were found. 1 '' is expected
I've seen this question posted previously but I've implemented all the accepted answers in my code and I'm still getting the error.
I have a number of classes (Client, Supplier etc) that each have a ...
1
vote
1
answer
100
views
How to indicate dependent entity in one to one relationship using shadow foreign keys only?
I have specified:
public class Cart
{
public int Id { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}
public class ApplicationUser : IdentityUser
{
public ...
1
vote
0
answers
269
views
Entity Framework Core 3.1 not working with already defined snake case database(sql server) schema
I have an exiting database and I wanted to perform crud operations on it. I am using asp.net core 3.1
web api. All my database tables are defined in snake case naming convention e.g my_table_name
...
0
votes
0
answers
203
views
EF core won't map inherited types in a Table-per-hierarchy and discriminator configuration
I have a base class with some properties and 10 derived types, 2 of them have a navigation property to another table, both of them are configured the same way, one is working and the other is not.
...
2
votes
1
answer
445
views
How to customize the default AspNetUsers data type lengths in ASP.NET Core
I know how to add and edit custom columns to AspNetUsers. I am asking how to change the default ones. I tried using the Fluent API in the DbContext file, but nothing changes. My Visual Studio is - ...
0
votes
3
answers
761
views
How to setup in EF Core, with Fluent API the default value for is required globally?
I created my first initial migration with some tables and columns, but I saw a thing, all my fields are not null and to every field which I want nullable (almost all) I need to specify the IsRequired(...
1
vote
0
answers
40
views
EF Fluent API Mapping with 1 constant field
we have a SQL database setup like this
Table 1 Tasks
-------------
TenantId int
TaskId int
TypeId int
Table2 TaskTypes
----------------
TenantId int
TypeId int
Name varchar(100)
Language varchar(2)
...
2
votes
0
answers
71
views
Same values for viewmodel and model constraints
I am developping a .net core app with 4 projects
core (where models are defined)
infrastructure (contains migrations and fluent api for core entities)
app (business logic)
web (razor pages and ...
0
votes
1
answer
181
views
ASP.NET Core : Fluent Api relationships configuration
There are a lot of examples how to use Fluent API in the internet, but mostly shows how configure one relationship between two models. In my case I need 3 relationships between 2 models. How to ...
-1
votes
1
answer
365
views
EF Core: combining 2 configuration extension method calls in one extension method call
I am using EF Core Code-First Approach to configure/map an entity class named Student to SQL Server table named Student. The Student entity model class has a string column named Name that will be ...
1
vote
1
answer
358
views
How do you check if a property has IsRequired() on an object using reflection?
I have a string property it is configured as IsRequired() using FluentAPI. How do I check if this property is required? I'm iterating through all properties of my object using reflection.
0
votes
1
answer
195
views
Unable to determine the relationship represented by navigation 'Role.CreatedBy' of type 'User'
I am using .NET 6 to develop EF Core MVC program, The concept is single User can have multiple roles, and the role data is create by a User from another system.
I have a base class EntityBase.cs :
...