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 to set value of an additional field in EF object

I have a Comment object with an optional user. On setting the user, I would like to set an additional field with the user's name so that if the user is later deleted the comment will be identifiable to humans. public class Comment { public int…
Julian Mann
  • 6,256
  • 5
  • 31
  • 43
0
votes
1 answer

How to use NotMapped Properties in a Composite Foreign Key

I'm creating a Codefirst from database EF project. The database this is being generated from I am unable to alter in anyway. I have manually created most of the relationships between the tables, however I have hit a wall with a table. Have two…
EZE
  • 69
  • 10
0
votes
1 answer

Entity Framework - Fluent API - The navigation property is not a declared propety on type

I am doing an web server with MVC4. I have 3 classes- User, MobileApp, Device. User and Device classes are with one-to-many relation (same like User and MobileApp classes). I am using fluent API to map the classes: public class User { public…
laik
  • 111
  • 13
0
votes
0 answers

Which one is better approach among Entity Framework 6.1.2 code first?

In ASP.Net MVC we can create ENTITY FRAMEWORK through CODE FIRST approach by both ways like FluentApi (with OnModelCreating() method) and migration script like Enable-Migration Nuget command(with DTO object)? Both of them give same result. I can see…
0
votes
1 answer

insert data to many to many join table

This is my tag table, one tag can have multiple posts: public class Tag { public int TagId { get; set; } public string TagName { get; set; } public IList Posts { get; set; } } This is my Post class, one post can have multiple…
neo
  • 75
  • 2
  • 9
0
votes
1 answer

Custom type mappings in EF6 using Fluent API

I really don't know how to better phrase the title, so i'm sorry in advance for any incorrectness. here is my problem: I have the following entities: public sealed class AppUser: DomainEntityBase { public bool ExternalLoginsEnabled { get; } …
sergio
  • 1,026
  • 2
  • 19
  • 43
0
votes
1 answer

how to properly configure using fluent api as data annotation not working properly

This is what i was trying to achieve but entity framework didn't let me do this: modelBuilder.Entity() .HasMany(u => u.Following) .WithMany(u => u.Followers) …
duke
  • 1,816
  • 2
  • 18
  • 32
0
votes
1 answer

Entity Framework Inheritance - Resolve Relations between entities with same parent

Here is my model I need to map this model to Entity Framework, but my results are building only one table named Fluxo, and there are lots of ugly FKs. Besides, I don't know how can I map my PK, defined at Fluxo class Here is my mappings public…
Jedi31
  • 735
  • 1
  • 6
  • 22
0
votes
1 answer

Cant get Table per Type (TPT) Inheritance Strategy - Code First Migration

I have the class public class Company { public int Id { get; set; } public string Name { get; set; } public DateTime CreatedOn { get; set; } public DateTime? DeactivatedOn { get; set; } public DateTime? UpdatedOn { get; set; } …
Fernando.M
  • 157
  • 3
  • 9
0
votes
0 answers

Entity Framework Fluent migration default value

I'm trying to generate automatically a default value for metadata columns in my code first database. It seems like code first migration fluent api does not handle HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed) Every table in my DB…
BenoitM
  • 97
  • 1
  • 10
0
votes
1 answer

EF Fluent Mapping not loading all children with eager loading using Include

I've created two entities which are related to each other by joining using three columns, both are views on the database. For the Travel I have the Id, FromCityId and ToCityId, for TravelCost I have the TravelId, FromCityId and ToCityId. The fluent…
ivi.hamiti
  • 552
  • 1
  • 4
  • 7
0
votes
2 answers

Loading a list of entities containing the parent as a property

I'm having difficulties acchieving certain functionality when using Entity Framework's Code First approach. Using the Fluent API I was trying to accomplish that the Agencies property of a User loads all Agency entities whose Principal or Agent…
bojank
  • 375
  • 1
  • 3
  • 9
0
votes
1 answer

Entity Framework One to Many Relations ship Fluent API with composite keys

Below are the classes that I am using. I want to create a one way reference from Stratification to PatientClientPhysician. I can also do a one to many relationship if that is required by Entity Framework but this will always be a 1-1 even though…
Adam Nester
  • 123
  • 1
  • 10
0
votes
1 answer

How to add one to one mapping between entities

I am trying to create a 'Register New User' feature using entity frame work. Each new user should have one entry in UserAccount table and one in UserProfile. Both are linked by foreign key column UserAccountId. Each new user profile can be approved…
Maheep
  • 5,539
  • 3
  • 28
  • 47
0
votes
1 answer

EF6 One to One or Zero Relationship (Fluent API)

I have such classes (simplicified): public class Transaction { public int LocalId { get; set; } public int MachineId { get; set; } public virtual Machine Machine { get; set; } public int? MoneyId { get; set; } public…
Lukas
  • 621
  • 2
  • 12
  • 29