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

How do I set up the relation using Fluent API between an Employee entity and an ICollection?

I am using entity framework and I have an Employee entity among other entities. One navigation property that I want Employee to have is a list of Employees that this Employee manages. This is the Employee class (it actually uses an EF prefix, but…
Drew
  • 1,277
  • 3
  • 21
  • 39
0
votes
1 answer

EF6 Fluent Api - I need to set Default value in FluentApi in order to Map Child to be used instead of Parent

Here's part of the setup. Names are simplified: I have following classes: MyClass MySubclass1 : MyClass MySubClass2 : MyClass MyClass is part of another class (and table), which I will leave out. I'm trying to do an EF6 query (using…
Recipe
  • 1,398
  • 3
  • 16
  • 29
0
votes
1 answer

Entity Framework Fluent API relationship mapping HasRequired().WithRequired() not behaving correctly without Map()

Blog Model using System.Collections.Generic; namespace DataLayer { public class Blog { public int BlogKey { get; set; } public string Title { get; set; } public string BloggerName { get; set; } public virtual…
blogbydev
  • 1,445
  • 2
  • 17
  • 29
0
votes
2 answers

How to relate model property to same model in ASP.NET MVC?

Sometimes, you want to store who registered or created a user account. It's either the user registered himself/herself or some other user account registered him, such as Admin accounts. So, the User table would something like: public class User :…
0
votes
1 answer

Entity Framework fluent api how to conditionally map multiple properties to a single table

Using fluent api, how do I map multiple properties of the same data type to a single table conditionally. Database Model: ListType would include the Grouping names i.e. Allergens ListItem would include all possible values for the given…
alex.davis.dev
  • 411
  • 7
  • 18
0
votes
0 answers

Mapping Entity Framework from Existing Database with Custom Field Structure

I'm using Entity Framework 6 with a Code First approach. We use a commercial, off the shelf software solution that I'm rolling up into our own custom application. In addition to having the basic tables for Employee, Salary, JobDetail where this is…
0
votes
1 answer

Entity Framework 6 NotMapped attributes

Is there a way using the fluentAPI within a DbContext to manually include ICollections that have been [NotMapped] in the model? I know how to manually ignore properties using the fluentAPI modelBuilder.Entity().Ignore(e =>…
0
votes
1 answer

How to solve multiple cascade paths with entity code first

A Template can have zero or many Document and zero or many MetaIndex. A Document can have zero or more Index, and a MetaIndex can also have zero or more Index: This represent a potential cascade problem because deleting a Template will delete its…
Erre Efe
  • 15,387
  • 10
  • 45
  • 77
0
votes
2 answers

Entity Framework Fluent API configuration

Here is the thing bugging me, I have 2 entities --- 'Master' and 'Slave', let me list them first: public class Master { public Guid Id {get;set;} public virtual ICollection Slaves { get; set; } public virtual Slave ParentSlave {…
wxdtony
  • 1
  • 1
0
votes
1 answer

Exception - A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'Id'

Okay, this is the situation..I'm running into a strange exception, and trough various other answers here on stackoverflow I've figured out that it must have something to do with the mapping between my Project-entity and the one-to-one relation to an…
Rob
  • 6,731
  • 12
  • 52
  • 90
0
votes
0 answers

Changing column existint in EF, engineering reverse

I have one columnt call "Name" in EF using engineering reverse, i need to change HasMaxLength 50 to HasMaxLength 100. I did change this.Property(t => t.Name).HasMaxLength(100); But not working, how i can update column name 50 to 100. Thank's
0
votes
1 answer

System.NullReferenceException when Inserting a new item for many-to-many relationship in entity framework

When adding an item for many-to-many relationship, I receive this error An exception of type 'System.NullReferenceException' occurred in gEchoLu.dll but was not handled in user code with no further details. Here is the code that throws the…
renakre
  • 8,001
  • 5
  • 46
  • 99
0
votes
1 answer

One to zero or one relationship entity framework

I am trying to enforce a one to (zero or one) table relationship using code first/fluent api and the intended table is as below. Student may only have a contact (StudentContact) or not But Every contact (StudentContact) must have a Student StudentID…
vincentsty
  • 2,963
  • 7
  • 34
  • 51
0
votes
2 answers

foreign key to application user id throwing key errors when updating database

I'm using code first to create a foreign key on YogaSpace that links the ApplicationUsers id to ApplicationUserRefId in the YogaSpace class. So every time I create and insert a new YogaSpace it fills the ApplicationUser id with the id of the person…
0
votes
0 answers

entity splitting into one table

Using EF 6.1.2. CodeFirst. I have these models: public class Automobile { public int Id { get; set; } public string Make { get; set; } public string Model { get; set; } public string Vin { get; set; } public int Year { get; set;…
Lorne Redmond
  • 263
  • 1
  • 3
  • 13