Many-to-many relationships in EF Core 2.0 – Part 4: A more general abstraction

In the last few posts we saw how to hide use of the join entity from two entities with a many-to-many relationship. This post doesn’t add any additional functionality, it just abstracts some of what we saw so it can be re-used more easily.

Continue reading

Advertisements

Many-to-many relationships in EF Core 2.0 – Part 3: Hiding as ICollection

In the previous post we ended up with entities that hide the join entity from the public surface. However, it was not possible to add or removed entities through this public surface. To enable this we need an ICollection implementation that acts as a true facade over the real join entity collection and delegates all responsibilities to that collection.

Continue reading

Many-to-many relationships in EF Core 2.0 – Part 2: Hiding as IEnumerable

In the previous post we looked at how many-to-many relationships can be mapped using a join entity. In this post we’ll make the navigation properties to the join entity private so that they don’t appear in the public surface of our entity types. We’ll then add public IEnumerable properties that expose the relationship for reading without reference to the join entity.

Continue reading

Many-to-many relationships in EF Core 2.0 – Part 1: The basics

As of EF Core 2.0, many-to-many relationships without an explicitly mapped join table are not supported. However, all is not lost. In this series of posts I will show:

  • Mapping many-to-many relationships with a join entity/table
  • Abstracting/hiding the join entity
    • In a simple way for read-only access to the relationship
    • In a more involved way that allows entities to be added and removed from each end

Continue reading

Secrets of DetectChanges Part 3: Switching off automatic DetectChanges

In parts 1 and 2 of this series we looked at what DetectChanges does and why the context calls DetectChanges automatically. In this part we’ll look at how automatic calls to DetectChanges can be switched off and what you then need to do differently in your code.

Continue reading

Secrets of DetectChanges Part 2: When is DetectChanges called automatically?

Part 1 of this series on DetectChanges described why DetectChanges is needed to discover the changes that have been made to POCO entities. This part will expand on that information and look at when it is important for the context to know about these changes. This will provide the basis for detailing when the context calls DetectChanges automatically. Continue reading

What’s the deal with mapping foreign keys using the Entity Framework?

Since EF4 it has been possible to map foreign key columns to properties of entity classes. But is it really a good idea to do this? In this post I’ll explain the reasons for keeping foreign keys out of your object model and contrast that with how mapping foreign keys may make your life easier.

Continue reading