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

EF-CF-Set 'ignored' property from another table value

I am using Entity Framework Code-First approach. Below is my sample Model. public class LocalizableEntity { public int Id{get;set;} // this property is 'Ignore'd. Need to set this. public string Name{get;set;} // this is…
Ananthan Unni
  • 1,304
  • 9
  • 23
0
votes
0 answers

How can I export all Entity Framwork EntityTypeConfiguration mapping classes to a csv with the mapping details of each properties in C#?

Sample Class: public class DocumentMap : EntityTypeConfiguration { public DocumentMap() { // Primary Key this.HasKey(t => t.ID); // Properties this.Property(t => t.ID) …
Ajo George
  • 15
  • 5
0
votes
1 answer

Specify the column to use when joining

I have some tables to specify standard email messages and the addresses from which they should be sent: Email.Message ------------- MessageId Name FromAddressId Email.Address ------------- AddressId These tables are modeled in code using these…
zimdanen
  • 5,508
  • 7
  • 44
  • 89
0
votes
2 answers

One to One relationship in Entity Framework MVC

I want to create one to one relationship in EF with MVC but getting little bit confused here are my model... public class Event { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } …
0
votes
2 answers

Unexpected foreign key generated for one to many relationship

I have declared two classes - Person and Vehicle as shown below public class Person { public Person() { this.Vehicles = new HashSet(); } [Key] public int PersonID { get; set; } [Required, MaxLength(50)] …
0
votes
1 answer

Entity frame work code first relationship problems

Using the entity framework i am experiencing some problems with table relations. It is between the two tables, Employee and AspNetUser. I get the following error: Unable to determine the principal end of an association between the types…
Diemauerdk
  • 5,238
  • 9
  • 40
  • 56
0
votes
1 answer

EF6 Code First Composite Primary AND Foreign Keys: Foreign Key must be mapped

Well, after a morning of beating my head against the wall, I'm tossing this out there. I have a DB Table (Table1) with a composite PK (Column1, Column2, Column3). (Column1,Column3) is ALSO a FK to another table (Table2). Trying to use Code First…
0
votes
1 answer

EF6 One-to-One Optional Relationship one-directional navigation properties

I have the following Domain models in a project I am working on, they are public class Person { public int Id { get; set; } public string FirstName { get; set; } public string Surname { get; set; } public virtual User { get; set;…
0
votes
0 answers

How to allow multiple FK in a table to cascade on delete?

I'm not certain if the title is correct as I'm unsure if the diagnostics of mine are reliable. Feel free to comment on that. While declaring a table using Fluent API like so: CreateTable("dbo.Things", c => new { Id = c.Guid(nullable: false,…
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
0
votes
1 answer

How to declare a one-to-many in Fluent API so that it's not required?

Suppose we have the two classes below. class Donkey { public Guid Id { get; set; } } class Monkey { public Guid Id { get; set; } public Donkey Donkey { get; set; } } I can configure the relation as follows. protected override void…
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
0
votes
1 answer

How to declare one-to-many using Fluent API without changing the model?

I have two classes as follows. class Donkey { public Guid Id { get; set; } } class Monkey { public Guid Id { get; set; } public Donkey Donkey { get; set; } } Now I want to configure the schema so that the relation is set in the database.…
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
0
votes
1 answer

How to model more entities to reference same kind of collections within single table

I'm not very experienced with EF and I'm trying to figure out what is the proper way or what are the options for creating entity, collection of which can be contained in other entities (different tables). Let's say I have three existing classes…
0
votes
1 answer

Entity Framework 7 DbContext OnModelCreating specify foreign key for ApplicationUser field

I am trying to achieve something very similar to what is happening in this EF7 fluent API documentation, but it is not the exact case. I have a model that looks like this: public class BlogPost { public int Id { get; set; } public string…
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
0
votes
1 answer

How to change database column name via Fluent API

I have a following code: public abstract class Entity { public virtual int Id { get; set; } } public class Category : Entity { public string Name { get; set; } public virtual ICollection Children { get; set; } public…
user2457382
  • 329
  • 4
  • 14
0
votes
1 answer

The Entity create an additional table for many to-many relationships

Today I got a question about how to create a many to many mapping using Entity Framework Code First fluent api. The problem is that the entity create an additional table beyond that was set for me. public class Person { public Person() { …