How to define Many-to-Many relationship through Fluent API Entity Framework?

The terms Left and Right in MapLeftKey and MapRightKey in the many-to-many mapping with Fluent API can be misunderstood and I guess your problem is caused by this misunderstanding. One might think that it means they describe the columns that are “left” and “right” in the many-to-many join table. That’s actually the case if you … Read more

Entity Framework Code First – Advantages and disadvantages of Fluent Api vs Data Annotations [closed]

Everything what you can configure with DataAnnotations is also possible with the Fluent API. The reverse is not true. So, from the viewpoint of configuration options and flexibility the Fluent API is “better”. Configuration examples (for sure not a full list) which are possible in the Fluent API but not with DataAnnotations (as far as … Read more

Entity Framework Core 2.0: How to configure abstract base class once

If I understand correctly, the Status is just a base class and not a base entity participating in Database Inheritance. In such case it’s important to never refer to Status class directly inside entity model and configuration, i.e. no DbSet<Status>, no navigation properties of type Status or ICollection<Status>, no modelBuilder.Entity<Status>() calls and no IEntityTypeConfiguration<Status>. Instead, … Read more

Setting unique Constraint with fluent API?

On EF6.2, you can use HasIndex() to add indexes for migration through fluent API. https://github.com/aspnet/EntityFramework6/issues/274 Example modelBuilder .Entity<User>() .HasIndex(u => u.Email) .IsUnique(); On EF6.1 onwards, you can use IndexAnnotation() to add indexes for migration in your fluent API. http://msdn.microsoft.com/en-us/data/jj591617.aspx#PropertyIndex You must add reference to: using System.Data.Entity.Infrastructure.Annotations; Basic Example Here is a simple usage, adding an … Read more

How to do a join in linq to sql with method syntax?

var result = from sc in enumerableOfSomeClass join soc in enumerableOfSomeOtherClass on sc.Property1 equals soc.Property2 select new { SomeClass = sc, SomeOtherClass = soc }; Would be equivalent to: var result = enumerableOfSomeClass .Join(enumerableOfSomeOtherClass, sc => sc.Property1, soc => soc.Property2, (sc, soc) => new { SomeClass = sc, SomeOtherClass = soc }); As you can … Read more