Questions tagged [ef-fluent-api]

A way to configure Entity Framework beyond its conventions with a method chaining API

Use the tag for questions that ask about:

  • Model-wide settings
  • Property mapping
  • Type mapping
  • Relationships

The EF-Fluent API can be used in both c# and VB.NET.

The MSDN documentation

833 questions
2
votes
1 answer

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 - Microsoft Visual Studio Community 2022 (64-bit) -…
2
votes
0 answers

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 viewmodels) I am defining model constraints with…
JMC
  • 21
  • 4
2
votes
1 answer

EF Core mistaking property as PK because of name

I have an entity named User and a value object named UserRef containing UserId. EF is picking up the UserId on the UserRef and trying to map it to a User. This isn't intended as this entity is for DDD, and I have no interest in using it as a…
Beakie
  • 1,948
  • 3
  • 20
  • 46
2
votes
2 answers

Getting Error when updating Migration in to database : Foreign key constraint may cause cycles or multiple cascade paths

This issue can be replicated easily, but I do not know the correct way to resolve it. Classes: public class Employee : IEntity { public Guid Id { get; set; } public Guid ApplicationUserId { get; set; } public ApplicationUser…
2
votes
1 answer

Many-to-many with TPH inheritance in EF Core

I am having trouble with setting up a many-to-many join table with EF core if one side of the join table is a derived class in table-per-hierarchy set up. Here's the set up: class Chore { Guid Id; } class LaundryChore : Chore { //…
2
votes
3 answers

Entity Framework : Invalid column name *_ID even with fluent api or data annotations

Odd issue that I've been looking at all day. I am working with Entity Framework 6. The issue I have is that I have three entities: public partial class Order : ILocationBearingObject { public int Id { get; set; } // other properties and…
EHaltom
  • 147
  • 10
2
votes
3 answers

How to Fetch a Lot of Records with EF6

I need to fetch a lot of records from a SQL Server database with EF6. The problem that its takes a lot of time. The main problem is entity called Series which contains Measurements. There is like 250K of them and each has 2 nested entities called…
Fallingsappy
  • 181
  • 3
  • 21
2
votes
1 answer

Alternative way to specify per-table schema

Using EF Core, Fluent API, specifying a schema at table level is done like: modelBuilder.Entity().ToTable("MyRecord", "mySchema"); Is there an alternative way to specify schema for a table, or multiple tables without having to string the…
JMP
  • 1,864
  • 2
  • 8
  • 16
2
votes
1 answer

ManyToMany Relation in EF Core fluent API

I'm facing with a probleme in entity framework Core with fluent API. I Want to configure a Many to many relation dynamically so I used the following code : var relationEntityBuilder = entityTypeBuilder1.HasMany(lambdaManyFirst) …
2
votes
1 answer

EF Core 3 Clustered indexing using fluent API not working

I have a .Net core 3.1 API with EF core code first migrations enabled where I am trying to add a clustered index on a non PK column. I have a Vehicle entity: public class Vehicle { // PK and has clustered index by default [Key] public…
bit
  • 4,407
  • 1
  • 28
  • 50
2
votes
1 answer

Entity Framework Core: one-to-one relation required

Entities: Address and Market: public class Address { ... // Navigation properties public Guid MarketId { get; set; } public Market Market { get; set; } } public class Market { ... // Navigation properties public Guid…
2
votes
1 answer

EF Core Code First Oracle - Cannot set nullable an existing colum

I set an existing property decimal to decimal?: public decimal? TotalAmountTTC { get; set; } Then I created a migration with add-migration, it generated me this : migrationBuilder.AlterColumn( name:…
Matthieu Charbonnier
  • 2,794
  • 25
  • 33
2
votes
2 answers

Issue with foreign key deployment to SQL server - Code First - Empty foreign key

I have rest API in .NET core and EF Core 3.0, I am getting one weird issue. Below is my entities. [Table(name: "BizObjects")] public class BizObject { [Key, DatabaseGenerated(DatabaseGeneratedOption.None)] [Required] [StringLength(06)] …
Bharat
  • 5,869
  • 4
  • 38
  • 58
2
votes
1 answer

How to configure this model relationship using FLUENT API

The user(AskedUser) can have many questions asked by other users(Asker). Users(Asker) can ask questions to other users(AskedUser). So the QuestionModel should have foreign key to asked user id and foreign key to user who asked the question. Do I…
Ronald Abellano
  • 774
  • 10
  • 34
2
votes
3 answers

AspNet Identity - Custom IdentityRoleClaim & IdentityUserRole & IdentityUserClaim that duplicated foreign key

currently, I am using AspNetCore and the configuration dbcontext as below: public class AppDbContext : IdentityDbContext,…