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
4
votes
2 answers

Remove Auto Increment in EF Core 1.0 RC2 (former EF 7 RC2)

In Entity Framework Core 1.0 RC2 (former Entity Framework 7 RC2), by default, all integer primary key are auto increment field. I tried everything to remove it. From using data annotation to fluent API, nothing works. Using data annotation: [Key,…
Sam
  • 1,826
  • 26
  • 58
4
votes
0 answers

Eager Loading using EF6 Fluent Api with a Composite Key Fails to Load Related Entity

I must be creating the composite key incorrectly or connecting it to the related entity incorrectly. I can get it to work in a simplified scenario of a single key, but the composite key fails. I'll show both working and non working versions. My…
4
votes
1 answer

Does EF Core support an abstract base entity which is generic?

I remember there were problems with generic entities in previous EF. How about EF Core? I can't find docs related to this matter. For example: public abstract class Parent { public int EntityId { get; set; } public TEntity Entity { get;…
4
votes
1 answer

Fluent api Cascade delete on relationships to one table

I have the following configuration. I have a User. The user has a postal Address and a Physical Address (see below). public class UserProfile { public Guid UserProfileId {get; set;} public Guid PostalAddressId {get;set;} public virtual…
Skbenga
  • 105
  • 1
  • 7
4
votes
1 answer

Entity Framework 6 DbUpdateConcurrencyException When Adding New Rows To Database

Here's my problem: Every time I attempt to add a row to the database, I get this exception: DbUpdateConcurrencyException No one else uses this development database except me. Please help. I'm at my wits end here. Here's the code: using (var context…
mmmoore
  • 41
  • 1
  • 3
4
votes
1 answer

Tell EF6 Not to Persist Base Class but set FluentAPI contrains

I have a base class called "Entity" in which I put standard fields that should be inherited by ever entity (ex. Id, CreateAt, UpdateAt). I prefer to use FluentAPI as it is said to be more powerful then annotations and it enables clean easily…
Dblock247
  • 6,167
  • 10
  • 44
  • 66
4
votes
3 answers

Foreign keys to same Entity with one required and another optional

I'm trying to create two entities as below and add referential constraints to them using Fluent API. The design it to enforce required Primary Contact with optional Secondary Contact with added requirement that Primary and Secondary may be referring…
Gururaj
  • 539
  • 2
  • 8
4
votes
2 answers

entity framework code first fluent api

I am using the fluent api for the first time . I am able to establish relationshionship using one to many and many to many relationship. But I have a clarification using one-to-one relationship. I have two tables tableA and tableB wherein tableA has…
user1907849
  • 960
  • 4
  • 19
  • 42
4
votes
1 answer

How to utilize existing keys defined in OnModelCreating (Fluent Api EF) to work with ODataModelBuilder in OData v4?

I have to implement an OData API in a Web API project. There is very good article about doing it here(entity relations) and here(composite key). But all the sources are using data annotations to set keys. In my project all the constraints on…
Ankit
  • 2,448
  • 3
  • 20
  • 33
4
votes
1 answer

Cascade delete using Fluent API

I have two entities. Profile and ProfileImages. After fetching a Profile I want to delete ProfileImages through Profile without it just removing the reference to Profile (setting it to null). How can this be done with fluent API and Cascading…
chuckd
  • 13,460
  • 29
  • 152
  • 331
4
votes
2 answers

Create one to one relationship optional on both sides in EF6

Is there a way to map two entities to have one to one relationship optional on both sides using fluent API in Entity Framework 6? Code example: // Subscription (has FK OrderId) this.HasOptional(t => t.Order) .WithOptionalDependent(t =>…
Filipe Borges
  • 2,712
  • 20
  • 32
4
votes
2 answers

How do I map this redundant parent-child relationship using Fluent API

Any suggestions on how I can double-map this parent-child relationship, where the parent has a normal 1-many relationship (which is working), but then I need a direct 1:1,0 link from the parent to a particular child. Public Class Source
4
votes
2 answers

Entity Framework Code First Fluent API configuration for one to one identifying relationship

I have the following class structure: How to configure Fluent API to put identifying relationship in Cards table? I mean Cards Table PK: Id, CustomerId Cards Table FK: CustomerId I would like the previous Card be deleted when I assign a new one…
4
votes
1 answer

How to POST/PATCH to a many-to-many relationship entity on an Azure Mobile Services?

I've been following the Field Engineer example project from the Windows Development Center to guide into mapping many-to-many relationships on my model. What's been bothering me is how to insert entries into many-to-many relationships. Take my model…
4
votes
1 answer

Add additional column to existing many to many relationship - EF Code First

I'm using Entity Framework 6.1.1. I need to add an extra field to a junction table, which I correctly created with Fluent API. I know that this is not possible with Fluent API and that I have to create a model class, but the problem is that I cannot…