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

Entity Framework: TPC MapInheritedProperties model super class properties

Summary: in Entity Framework I use TPC to create two classes derived from the same base class. In fluent API I map inherited properties, but how to model the properties of the base class? More extensive description In Entity Framework I have a class…
Harald Coppoolse
  • 28,834
  • 7
  • 67
  • 116
0
votes
1 answer

Entity Framework 6 - Add parent with children which contains other children

I have a problem with add object to DbSet. class Word { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid ID {get;set;} public virtual ICollection Translations {get;set;} public virtual…
Pyotreq
  • 146
  • 1
  • 1
  • 6
0
votes
0 answers

Why relationship that were set with Fluent API are being lost after restarting app?

I have two classes: class Owner { [Key] public int OwnerID { get; set; } [Required] public string Name { get; set; } public virtual ICollection Cars { get; set; } public Owner() { Cars = new List(); …
Eyeless
  • 33
  • 5
0
votes
1 answer

Entity Framework 6 recreate database

Database is made with code first using Fluent API. Migrations are enabled and init file is in migrations folder. Now we need to drop database and create it again with new definitions (mapping, required entities, etc.). Do I need to delete migrations…
0
votes
1 answer

Mapping a many to one relationship over a view in entity framework 6 fluent api

I have an issue with a hierarchical setup here, and I can't get my head around how to configure that correctly with entity framework fluentapi, or if it is even possible. I have my self referencing table where I have my entity and a reference to the…
Egi
  • 1,256
  • 9
  • 20
0
votes
1 answer

Entity framework 6 code first one to one instead of one to many

I got over a project where EF6 code first is used. I have 2 classes where a relationship one to many is set, the same is set in Fluent API. When I create both parent/child in the same step everything is fine and saved, but when I create the parent…
Mony
  • 93
  • 1
  • 11
0
votes
1 answer

A list of the related AplicationUsers inside of an ApplicationUser

I Got another question today. I Want to Relate a List of ApplicationUser into the Application User... Something like this... public class ApplicationUser : IdentityUser { //Here are the Added Needed Values to IdentityUser to PlenaMenteTrabajando…
0
votes
1 answer

Create 2 Primary Key using EF Fluent API

I follow tutorial from this https://mva.microsoft.com/en-us/training-courses/implementing-entity-framework-with-mvc-8931?l=mBKHDFC3_9204984382. This is my code namespace FluentAPI { class Program { static void Main(string[] args) { …
Intan
  • 143
  • 1
  • 2
  • 15
0
votes
0 answers

Fluent API - Use candidate key as Foreign Key

I have following two entities. Employee and Address. Employee can have one or many addresses. What i need is to set their relationship via Fluent APIs. But i don't want EmployeeId (which is primary key in Employee) to use as foreign key for…
Fakhar uz zaman
  • 331
  • 5
  • 14
0
votes
0 answers

Setting delete rule to "Set null" in one to many relationship using code first

I have two entities which have one to many relationships public class Brand{ public virtual ICollection Product{ get; set; } } public class Product{ public virtual Brand Brand{ get; set; } } > modelBuilder.Entity() > …
0
votes
1 answer

Mapping exception in Entity Framework

I have a big database for a multi lingual application that gets it's texts from the server , inserts into the database, then based on user preferred language, finds appropriate text. Let me first describe the database then I'll say my…
Hesam Kashefi
  • 620
  • 8
  • 15
0
votes
0 answers

Use Fluent API Map method and define foreign key as a property in model together

When i use the following codes, everything works well but i have not the foreign key property in my model to work with it in my logic classes: Content Model: public virtual File AudioFile{ get; set; } Fluent API: HasOptional(p => p.AudioFile) …
Ramin Bateni
  • 16,499
  • 9
  • 69
  • 98
0
votes
0 answers

How to tell Entity Framework to ignore properties in a complex property

Suppose I have these three classes: public class ClassA { public int ID { get; set; } public string Name { get; set; } public ClassC ClassC { get; set; } } public class ClassB { public int ID { get; set; } public string Name {…
Jamie Twells
  • 1,924
  • 4
  • 26
  • 56
0
votes
2 answers

Have specific property configuration for all types that implement an interface except for one

I have a number of Types that inherit from the Interface 'IEventReportElement', which exposes the property 'IdEventReport': public interface IEventReportElement { long Id { get; set; } long? IdEventReport { get; set; } } This is a nullable…
DevilSuichiro
  • 1,049
  • 8
  • 21
0
votes
0 answers

How can use Entity Framework to configure 0 - 1 relation with non-normalized schema?

I realize there are many zero to one questions out there but I am not having any luck understanding them relating to my scenario. When I say "non normalized schema," I mean there is no Photo table which would be very simple to configure for me. It…
jwize
  • 4,230
  • 1
  • 33
  • 51