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

ScriptIgnore Attribute Being Ignored

I'm attempting to serialize a DTO however its falling down, claiming a circular reference issue - which is definitely valid. I have the following entities: public class User { [Key] public int UserID { get;set; } public string…
0
votes
1 answer

0..1 to many relationship with Fluent API with EntityFramework Core

I need to declare an 0..1 to many relationship using Fluent API with EntityFramework Core. Right now I have a 1 to many relationship and I cannot figure out how to change that to a 0..1 to many. modelBuilder.Entity() .HasOne(c =>…
BeebFreak
  • 111
  • 1
  • 6
0
votes
1 answer

Many to Many relation in EF made without links to the entity

I would like to shift from the common pattern in many to may relation using implicit joint table and instead I want to use the joint table explicitely and implement a kind of lazy load of many-to-many dependent entity. This is framed by the design…
Dmitry Dyachkov
  • 1,715
  • 2
  • 19
  • 46
0
votes
1 answer

Error adding entities to database

I'm getting the following exception message: An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as…
ddeamaral
  • 1,403
  • 2
  • 28
  • 43
0
votes
1 answer

Why can't I have property of type Type in my model for Entity Framework?

I'm setting up a model for a project and everything works as expected, except for the change below. I thought it'd be neat to specify the type as Type instead of its description as string. namespace DataBase.Entities { public class Lock { …
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
0
votes
1 answer

how to configure cascade delete with EF Fluent API

I have the following classes and EF convention created the tables fine - all good. Now I want to configure cascade delete on the ToDoList (so that when I delete a ToDoList, all the ToDoItems and UserToDoLists also gets deleted automatically). Must…
lee23
  • 409
  • 1
  • 3
  • 10
0
votes
1 answer

Entity Framework Relation with null or 0 Key

I am trying to work with an existing database and my ability to make changes are difficult. I am hoping to do some transitional work and being an ORM in however, i have hit an issue. I am using EF Fluent API (closer to the NHibernate way of doing…
0
votes
1 answer

How to configure Domain Classes to use ObservableCollection using EF?

I have started using Entity Framework Code First modeling technique and have seen many examples of implementing one to many (1-N) relationship using DataAnnotation and FluentAPI but all examples are using ICollection while modeling domain classes. I…
0
votes
1 answer

Configure 1 to 1 and many to many in 3 Entities using Fluent API

Am new to fluent API kindly bear with me. I have three entities Student, Address and Course, Student and Address should be 1:1 relationship and Student and Courses should be m:m(many to many). My question is should i define Courses and Address…
Michael Mburu
  • 460
  • 1
  • 4
  • 11
0
votes
1 answer

EF6 Fluent Mapping the incorrect keys for joins

I am trying to get EF6 Fluent Mappings to work for my current project. I have the following Order mapping: public class OrderMap : EntityTypeConfiguration { public OrderMap() { this.ToTable("OE_Orders"); …
Carson
  • 1,169
  • 13
  • 36
0
votes
1 answer

ASP.NET-Identity OnModelCreating Modelbuilder Generating Duplicate Foreign Keys

I have an ASP MVC 5 application but the model builder is creating duplicate foreign keys for the IdentityUserRole, IdentityUserClaim and IdentityUserLogin tables. E.g in the generated migration table below has RoleId as well as…
adam78
  • 9,668
  • 24
  • 96
  • 207
0
votes
1 answer

EF6 M:M Without Bridge/Junction Class, Unconventional FKs

Trying to wrap my head around M:M with EF6. I have an existing database and am manually handling the models in code, using the fluent API on model creating. As I've read and as makes sense to me, when a db schema contains a junction table without…
jleach
  • 7,410
  • 3
  • 33
  • 60
0
votes
0 answers

How assign not primary key of table as foreign key of another table

I have two tables: User and Profile public class User { public string Id { get; set; } public string UserName { get; set; } public string Email { get; set; } public string Password { get; set; } public Profile Profile { get;…
Grigory
  • 1
  • 1
  • 3
0
votes
0 answers

aggregate root with nested list to one table with fluent api

I have an aggregate root: Report. This Report entity has a list of Order entities. How do I save the Report, and get fluent api to insert one record in the database table for each order? Report Entity: {Orders, ReportId} Order Entity: {Order Id,…
Steve's a D
  • 3,801
  • 10
  • 39
  • 60
0
votes
2 answers

Two tables that have keys to each other on Entity Framework

I have the following classes: public class Condition { public int Id {get;set; } public Condition ParentCondition {get;set;} public Action ParentAction {get;set;} public string Whatever {get;set;} } public class Action { …
Ole Albers
  • 8,715
  • 10
  • 73
  • 166