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

ASP Boilerplate (EF) - Fluent Api - Self Referencing Table, not using primary key

So I have to import a table from another database. The table is self referencing using it's own key, but I can't trust the key, especially since the table I'm importing into will be for multiple datasets. I'm using entity framework and code first…
Salteris
  • 201
  • 2
  • 6
0
votes
1 answer

entity framework one to one with foreign key

It seems that Entity Framework have some conventions to deal with one to one relationship. I'm using Fluent API and I need my child entity to have PK and Also FK. Is it possible without using the [ForeignKey] attribute?
0
votes
1 answer

Fluent API One to Many mapping table

It's really helpful if anyone could explain me how to create a mapping (associated)table for one to many relationship using Fluent API.` public class Category { public int ID { get; set; } public string Name { get; set; } public List
0
votes
1 answer

Entity Framework 6 - One to Optional Relationship

I am fairly new to EF and using version 6 and am stuck on a one-to-none relationship. My overall structure is I have a Gallery object which has an ICollection of GalleryMediaItem entities inside it and each GalleryMediaItem has a MediaItem entity…
0
votes
2 answers

Entity Framework - Code first - One to Many relationship with shared primary key

Anyone know how to implement this scenario with EF Code First Fluent API: public class Referancial { // Identity public int KeyID { get; set; } public string Code { get; set; } public virtual ICollection Translations {…
0
votes
2 answers

Entity framework fluent API mappings for zero to one

I am quite new new to EF (basically just starting). I am having problems with following. Lets say that I have a table that describes a product, this product (based on type) can have a number of additional properties ( for a purpose of this enquiry I…
SebSky
  • 161
  • 1
  • 7
0
votes
1 answer

Entity Framework Navigation Property without Foreign Key Constraint

I have a code first EF Model with a simple one(PartDetails)-to-many(Parts) relationship. While the system is offline the lookup (PartDetails) table is purged and re-populated by external job, violating the…
0
votes
1 answer

EF 6.1 Error Trying to Establish Recursive Relationship - Self-Referencing Table and FluentAPI

I'm having quite the issue trying to create a recursive relationship in Entity Framework 6.1. I'll need some different types of Categories, but have created a "base" abstract class for all of them. I'm using Table-Per-Type hierarchical strategy. A…
0
votes
1 answer

One-sided configuration with custom column names

I'm having trouble finding the right combination of Fluent methods to map my classes appropriately. Here's basically what I'm trying to do: Person table: PersonID, HomeAddressID (nullable), WorkAddressID (nullable) Address table: AddressID, Street,…
Joe Enos
  • 39,478
  • 11
  • 80
  • 136
0
votes
2 answers

How can I implement a 1..n bi-directional relationship in Entity Framework Code First

I am absolutely stumped in trying to figure out how to implement a bi-directional 1..n relationship in Entity Framework using Code First. For example, a team (represented by a Team entity) has a coach and a manager (both represented by a Person…
0
votes
1 answer

Delete Cascade on Code First - One-to–Zero-or-One

I have an Entity named Items, then I have several entities that have a foreign key (NOT NULLABLE) to this table key ItemId. Then I have another table named Soldiers that depends also on Items, but in this case it's a (NULLABLE) foreign key. When I…
0
votes
1 answer

Entity Framework Code First Fluent API One to Many

I have a ProductRequests table. It has a one to one relationship to ProductRequestDepartments. Which works correctly. I want to link ProductRequestDetails (which will have the actual Products (1 or more) of the ProductRequests. public partial class…
0
votes
2 answers

Entity Framework - Fluent API 1 to 0.1 Moderator / Person

I am receiving this error in my migrations: Person_EventModerator_Target: : Multiplicity is not valid in Role 'Person_EventModerator_Target' in relationship 'Person_EventModerator'. Because the Dependent Role properties are not the key properties,…
user1177440
0
votes
1 answer

Entity framework 6 - Some objects of the list returned by context have an empty property

I am retrieving a list of entities like this : var traductions = from t in context.Traductions where t.User.ID == user.ID && (DateTime.Now < t.EndDate) select t; var list =…
tobiak777
  • 3,175
  • 1
  • 32
  • 44
0
votes
1 answer

Map a sql view to already defined multiple entities in Entity Framework Code first?

I am using code first approach fluent API to map the sql tables to entities as follows: public class ProjectEntities : DbContext { public ProjectEntities () : base("name=ProjectEntities ") { } …
user1882705
  • 1,081
  • 4
  • 15
  • 43