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
3
votes
1 answer

How to set ForeignKey and Index properties using IEntityTypeConfiguration in EF Core 2.0

I am attempting to use the EntityConfiguration interface which is new in EF Core 2.0. Addendum Probably helpful to see the Message class public class Message { public int MessageId { get; set; } [Required] public string…
dinotom
  • 4,990
  • 16
  • 71
  • 139
3
votes
4 answers

EF6 preventing not to create Index on Foreign Key

I'm using EF6 code first approach to create database. When i add migration and update database it always create Non-cluster Index for every foreign key in the table by default. My Question: Is there any global setting for EF6 to not create…
Usman lqbal
  • 935
  • 1
  • 9
  • 31
3
votes
1 answer

How to configure a composite primary key containing a foreign key (EF Fluent API)

I have a one-to-many relationship between entities Curve and Point, defined as follows: public class Curve { public Curve() { Points = new HashSet(); } public int CurveId { get; set; } public string Name { get;…
harveyAJ
  • 833
  • 1
  • 11
  • 26
3
votes
2 answers

Multiple lists of same class in Entity Framework

I'm trying to create a data model of companies with relations to the same type in Entity Framework code first. I want to create the relation one-way, so when a company adds another as its customer, the other company doesn't get that company as a…
Kristoffer Berge
  • 1,046
  • 1
  • 20
  • 36
3
votes
0 answers

Information cannot have keys other than those declared on the root type, but it doesn't

Model builder is throwing the following error: An exception of type 'System.InvalidOperationException' occurred in EntityFramework.Core.dll but was not handled in user code Additional information: The derived type 'Namespace.myclass' cannot have…
3
votes
1 answer

Fluent API Table Scaffolding - HasBaseType

I have two entities in my project Student and Teacher which share a common base class, AccountModel. The base class contains properties that are required by both students and teachers (semantically, both students and teachers are account holders,…
Matthew Layton
  • 39,871
  • 52
  • 185
  • 313
3
votes
2 answers

How do I model deletion in an EF Core many-to-many relationship?

I've followed the docs for setting up my many-to-many relationship, using a join table that is exposed as an entity. But the docs don't mention what I should do about deletion. So for example, a Student has many teachers, and a Teacher has many…
3
votes
1 answer

Add Column Name Convention to EF6 FluentAPI

This question was asked here 4 years ago: EF Mapping to prefix all column names within a table I'm hoping there's better handling these days. I'm using EF6 Fluent API, what I'll call Code First Without Migrations. I have POCOs for my models, and…
jleach
  • 7,410
  • 3
  • 33
  • 60
3
votes
1 answer

Entity Framework TPH on top of TPT

This problem will be explained around 3 classes: Account, IndividualAccount, and Doctor: First two classes are abstract IndividualAccount is Account's subclass Doctor is IndividualAccount's subclass The first layer of inheritance (between…
3
votes
1 answer

Navigation property has been configured with conflicting multiplicities Fluent API

Hi! I have some relational issues between two tables, one - to - many. The whole concept is as follows: Table 1: Country: Besides it's own fields it also contains two ICollections where one points to a collection of regions and the other…
user2634538
  • 91
  • 1
  • 6
3
votes
1 answer

Virtual property won't lazy load in Entity Framework 6 (with caveat)

I'm stuck... Here's my model: public class Payment { [ForeignKey("RecipientId")] public virtual Account Recipient { get; set; } public string RecipientId { get; set; } [Key, Column(TypeName = "char"), MaxLength(36)] public…
Erik5388
  • 2,171
  • 2
  • 20
  • 29
3
votes
2 answers

Defining Self Referencing Foreign-Key-Relationship Using Entity Framework 7 Code First

I have an ArticleComment entity as you can see below: public class ArticleComment { public int ArticleCommentId { get; set; } public int? ArticleCommentParentId { get; set; } //[ForeignKey("ArticleCommentParentId")] public virtual…
Hamid Mosalla
  • 3,279
  • 2
  • 28
  • 51
3
votes
0 answers

Asp.net.identity override role and change primary key

I am actually trying to override the IdentityRole class coming with asp.net.identity to enable 'multi-tenancy' role. I already overrided the class as follow : public class ApplicationRole : IdentityRole, IIdentifiableEntity, ITenantable { …
Doum
  • 397
  • 3
  • 14
3
votes
2 answers

Define SQL table primary key as case sensitive using Entity Framework Code First

Is it possible to define a SQL case sensitive primary key in entity framework code first? I know that by default SQL is case insensitive when it comes to strings, just to be clear I don't want to change the entire DB definition to case sensitive,…
LiranBo
  • 2,054
  • 2
  • 23
  • 39
3
votes
1 answer

Multiplicity is not valid in Role in relationship: EF code first one to one relationship with same primary key and foreign key

I have two entities with one to one relationship where in target entity primary key and foreign key are same. Here is two entity and their fluent mapping. public class Register { public int Id { get; set; } public string Number { get; set;…