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

Entity Framework Optional Relationship Mapping

I have three POCO entity classes: public class User { public int Id { get; set; } public string UserName { get; set; } } public class BlogPost { public int Id { get; set; } public string Text { get; set; } public virtual…
Neilski
  • 4,385
  • 5
  • 41
  • 74
0
votes
1 answer

Entity Framework one-to-many join table with metadata

I'm trying to implement something of a join table in Entity Framework but I can't really seem to get any results back. I have two main objects: public class Device { [Key] public int Id { get; set; } public virtual…
Nebula
  • 1,045
  • 2
  • 11
  • 24
0
votes
2 answers

Setting PK is clustered using EF6 fluent api

It's been bugging me that I have to use migration to set a primary key to not clustered but I'm not able to use fluent API to set it. Is there any way/hack to extend fluent API to support setting primary key IsClustered property in a way that when…
mrtaikandi
  • 6,753
  • 16
  • 62
  • 93
0
votes
1 answer

Foreign Key with Fluent API - Code First

I am trying to establish foreign key to 2 classes using FluentAPI and bit confused on the way to implement it. ApplicationUser uses ASP.NET Identity model and has UserId as string public class ApplicationUser : IdentityUser { public virtual…
GeekzSG
  • 943
  • 1
  • 11
  • 28
0
votes
1 answer

Creating one to many relationship in Entity Framework using Fluent API

I have the following POCO Classes: public class Client { public string ClientId { get; set; } public string CompanyId { get; set; } public string LastName { get; set; } public string FirstName { get; set; } …
kurabdurbos
  • 267
  • 1
  • 14
0
votes
1 answer

Mapping same collection with two Navigation Properties

I have the following model public class Locale { public int Id { get; set; } public ICollection> Localizations { get; set; } } public class Localization { public int Id { get; set; } public Locale Locale {…
Paul Connolly
  • 359
  • 2
  • 8
0
votes
0 answers

Mapping an enum to a string

I am in the process of migrating some old legacy database/code to Microsoft Entity Framework version 6 and have come across the following problem. The code-behind defines an enumeration and a POCO object as follows: public enum AssetOwner { User…
Neilski
  • 4,385
  • 5
  • 41
  • 74
0
votes
1 answer

Entity Framework One to many fluent Api - foreign key

I would like to make connection between two entitites. I have Entity_1 and Entity_2 with relationship one - to many (one Entity_1 can have multiple Entity_2). So I have my entities: Entity class Entity_1 { public int Id { get;…
mskuratowski
  • 4,014
  • 15
  • 58
  • 109
0
votes
1 answer

EF code first Seed many to many relationship not working when fluent API is used

I have an issue with seeding the many to many tables, when I add the Fluent API. First I have created the two entities, and the many to many relationship between them like this: [Table("meta.DataCategory")] public partial class DataCategory :…
sirpadk
  • 809
  • 2
  • 7
  • 12
0
votes
1 answer

Foreign key mapping on Identifying Relationships

I am facing issue in foriegn key association for the below entites. For example there are Three entities namely One, Two and Three. Two is depend on One, like that Three is depend on Two . In Addition Two will many three's and One will have may…
Max_dev
  • 508
  • 7
  • 25
0
votes
1 answer

EF6 one-to-many fluent api with navigation properties

I'm trying to apply a one-to-many for my entities using EF6 and fluent API but keep getting this error: EmailTemplate_Attachments_Source_EmailTemplate_Attachments_Target: : The number of properties in the Dependent and Principal Roles in a…
Crispy Holiday
  • 412
  • 1
  • 9
  • 28
0
votes
0 answers

C# Code First - How to create unique together foreign keys

I have a model that has two foreign keys (as well as a primary key). I want to set the two fks unique together (meaning there can't be two columns with both having the same two fk values). I've tried everything but I keep getting: "The type…
0
votes
2 answers

Changing the Database Schema on a linking table (many-to-many) in EF

I am creating a many to many relationships with my EF Models. The linking table is being created which is fine, but it keeps putting it on the DBO Schema which I do not want. Yes, I could just modify the migration script after its generated but…
Jason H
  • 4,996
  • 6
  • 27
  • 49
0
votes
1 answer

Enum defined as IsOptional cannot be queried for null values

I have defined an Enum property on an Entity via Fluent API as IsOptional. The database reflects the IsOptional as it shows it as a nullable type. When I attempt to query this Entity property for null values I get the following error: The 'UserType'…
m4chine
  • 431
  • 1
  • 7
  • 16
0
votes
0 answers

EF Fluent API - Can I represent these tables?

Preface: I have no control over the database schema. In this question I've renamed the fields/tables to make it easier to understand. I've included the [Key] and [ForeignKey()] annotation in my example, but I'm really trying to define it in fluent…