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

Possible to set column ordering in Entity Framework

Is there any possible configuration to set database column ordering in entity framework code first approach..? All of my entity set should have some common fields for keeping recordinfo public DateTime CreatedAt { get; set; } public int CreatedBy {…
16
votes
4 answers

How do I configure fixed length columns in EF Core?

In the previous EF, I could do this: entityTypeBuilder .Property(b => b.Foo) .IsRequired() .HasMaxLength(10) .IsFixedLength(); That would generate a migration with something like Foo = c.String(nullable: false, maxLength: 10,…
15
votes
1 answer

Moving from EF6 to EF Core 2.0

I just started moving my MVC5 project with EF6x to MVC Core and EF Core but have a big problem with my entities configuration's. How you can migrate a EF6 Fluent configure to EF core? I need a guide with sample if possible. Here is one of my…
hitasp
  • 698
  • 2
  • 8
  • 19
14
votes
1 answer

How to retrieve Entity Configuration from Fluent Api

Using Entity-Framework 6 I'm able to set up the configuration through Fluent Api like this: public class ApplicationUserConfiguration : EntityTypeConfiguration { public ApplicationUserConfiguration() { this.HasKey(d…
14
votes
1 answer

EF Core 2.1: Self-referencing entity with one to many relationship generates additional column

I have the following entity: public class Level { public int LevelId { get; set; } public int? ParentLevelId { get; set; } public string Name { get; set; } public virtual Level Parent { get; set; } public virtual HashSet
12
votes
1 answer

Undo HasIndex in OnModelCreating

I am trying to configure a multi-tenancy application using Identity Framework Core. I have successfully created a custom ApplicationUser to override IdentityUser with TenantId using instructions here:…
Dan Soper
  • 639
  • 8
  • 18
11
votes
1 answer

HasOne not found in EF 6

I am very new to Entity Framework and I am trying to figure out relations. I have found this code: class MyContext : DbContext { public DbSet Posts { get; set; } public DbSet Tags { get; set; } protected override void…
user1140479
11
votes
1 answer

Composite Key EF Core getting error when using Fluent Api

So I have the following class in Entity Framework Core. I am trying to do a code first migration and can't for the life of me figure out how to make the fluent API for this work. public class Participants { public Activity Activity { get; set;…
11
votes
2 answers

One-to-One relationships in Entity Framework 7 Code First

How to configure One-to-One or ZeroOrOne-to-One relationships in Entity Framework 7 Code First using Data Annotations or Fluent Api?
11
votes
1 answer

Violation of primary key Entity Framework Code First

I have started with C# and I wanted to make my own DB. I have two models public class AModel { public Guid ID { get; private set; } public string Name { get; set; } public int Count { get; set; } public AModel() { …
Tomas Bruckner
  • 718
  • 2
  • 10
  • 22
11
votes
1 answer

Mapping object type property to varbinary(MAX) in Entity Framework

I have a situation where I have a type with a property of type object, eg. public class MyType { public virtual object MyProp{get; get;} } This type will have to be: Saved using Entity Framework to a database, as a byte[] (I have figured the…
tinonetic
  • 7,751
  • 11
  • 54
  • 79
10
votes
2 answers

One or Zero to One Entity Framework Code First FluentApi

I need to create fluentapi one or zero to one reference and have navigation properties on both of entities. EntityTwo should contain simple proerty to store foreign key (EntityOneId) public class EntityOne { public int Id { get; set; } …
Oleg Gochachko
  • 101
  • 1
  • 1
  • 5
9
votes
1 answer

One-to-one relationship in EF Core (The child/dependent side could not be determined for the one-to-one relationship)

I've been getting the following error message and I can't seem to grasp the reason why have I been getting it. Interestingly when adding migrations I didn't get any errors, but whenever I want to use the context I do get it. The child/dependent…
9
votes
1 answer

EF can you make a Mutli-column Index using shadow properties?

I'm trying to create a multi-column unique index using a shadow property. I know I can solve this problem with just adding a property, but I would like to see if this is possible in a way to keep my model clean. To create a multi-column index you…
9
votes
2 answers

System.Data.Entity.ModelConfiguration missing in EF core

Trying to load all the configurations dynamically on OnModelCreating for Entity framework core. what is the other way around if ModelConfiguration is missing.
Kenny
  • 819
  • 1
  • 9
  • 24
1
2
3
55 56