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

Using same C# Poco classes with in mongodb and Entityframework

My Domain Classes is as follow: public class Author { public int Id { get; set; } public string Name { get; set; } public IList Posts { get; set; } } public class Blog { public int Id { get; set; } public string Name {…
mesut
  • 2,099
  • 3
  • 23
  • 35
3
votes
3 answers

Followers Schema in Entity Framework

I am making an App which will have the Following functionality. But I am stuck at this. I have come up like this. public class User { public int Id { get; set; } public ICollection Followers { get; set; } public ICollection
Hamza Baig
  • 666
  • 1
  • 7
  • 13
3
votes
1 answer

DDD with MongoDB

I can't believe I didn't find good article about it. So it might be a 1000 times asked question. I'm writing a sample, which consists of Nancy MVC, plus Service Layer, Core Layer, DAL. Where DAL use MongoDB. What I'm trying to achieve is to…
3
votes
2 answers

EF 6 Codefirst -Setting default value for a property defined in base class using fluent API

I have a base class which has audit properties like public abstract class BaseModel { [Column(Order = 1)] public long Id { get; set; } public long CreatedBy { get; set; } public DateTime CreatedDate { get; set; } public long…
Abi P
  • 1,410
  • 3
  • 22
  • 36
3
votes
2 answers

How to set default length on all fields in entity framework fluent api?

Is it possible to set default length of all string fields (unless I say otherwise)? At the moment it really bugs me to go and add something like modelBuilder.Entity().Property(x => x.YardLine).HasMaxLength(256); to each and every string…
Tanuki
  • 717
  • 1
  • 9
  • 24
3
votes
2 answers

When an entity has more than one 0..1:n relationships to another entity, how to define them using Fluent API?

I'm working on an Azure Mobile Service and in my model I have an entity Message, which is related to itself following this statement: A Message may have a parent Message, a Message may be the parent to many Messages. My class got defined as…
Uriel Arvizu
  • 1,876
  • 6
  • 37
  • 97
3
votes
1 answer

Creating a UNIQUE Filtered Index for NULL values on Entity Framework

I'm trying to create a table that has a UNIQUE Filtered Index for NULL values (eg. Allow Null values to be duplicates) using Entity Framework. I am using Fluent API and have this entity property: modelBuilder.Entity().Property(c =>…
Cobo
  • 118
  • 1
  • 7
3
votes
1 answer

How to get IdentityUser roles' names in View?

Using ASP.NET MVC5 user identity, I am trying to display IdentityUser's role names in view. It seems like Identity user has Roles property, which represent collection of IdentityUserRole, instead of IdentityRole. The difference is IdentityUserRole…
3
votes
1 answer

No key defined for key on multiple columns

I am using C# and Entity Framework. I want to define a key for the SimulationParameter object as a combination of three columns (Name, StudyId, SimulationId). I don't need an ID column, since the combination of those three elements will always be…
Etienne Noël
  • 5,988
  • 6
  • 48
  • 75
3
votes
1 answer

Extend Entity framework 5 entity using partial class and map it to existing other entities

I haven't seen question like this been raised. So, I created one for EF fluent api developers and nopcommerce plugin developers. Here's what I'm trying to do: I have a product entity and can used by EF to generate database. I want to extending the…
Yuxuan Xue
  • 43
  • 1
  • 6
3
votes
2 answers

Entity Framework - adding an existing entity to one to one relationship in seed method

My Domain Classes: public class Address { [Key] public virtual string AddressId { get; set; } public virtual Site Site { get; set; } } public class Site { [Key] public virtual int SiteId { get; set; } public virtual…
3
votes
1 answer

Foreign key issues in EF6 CF

Excuse me for being a noob with EF when it comes to code first. My problem is I don't want to add foreign key properties to the model and according to MSDN this presents no problem using the fluent API, however I can not figure out the correct use…
3
votes
1 answer

Change Constraint Names using an Entity Framework Migration

I have built a database using EF Codefirst (In an MVC4 application). I've since learnt, that an external tool that will access this database has name-length limitations for columns & constraints. Column names must be <=20 chars Constraint names…
2
votes
0 answers

When I set two collections of the same entity entituy core tries to use the default column name

First I will expose the code that reproduces the problem. Then I will explain the problem. I have two entities, Employee and ContactForm (address, email, telephone...): public class Employee { public long Id { get; set; } public string…
Álvaro García
  • 18,114
  • 30
  • 102
  • 193
2
votes
0 answers

Configure Many-To-Many EF Relationship Between Separate Aggregates Without Using Navigation Lists

I have two entities from separate aggregate groups that have a many-to-many relationship: public class ClientNotificationMethod { public int ID { get; private set; } private ICollection _personIDs; //public virtual…