Entity Framework specify cardinality in a many to many relationship

k.c.

We have a many-to-many relationship, which we specify fluently like this:

Hasmay(A=>A.Bs).WithMany(B.As)

An "A" can have zero or more "B"'s. An "B" must have one or more "A"'s.

Is there a way to specify the cardinality for the "As" in "B"?

Gert Arnold

No, because under the hood it's a 1-n-1 association. That is, A has zero, one, or many AB junction records, and AB always has one B (and always one A).

So we're dealing with the rules of 1-n associations. There is no way to enforce a 1 - 1..n association (i.e. a parent must have at least one child), at least not in DDL. Consequently there is no way to enforce 1..n - 1..m associations. It's always 0..n - 0..m. Only by business logic you can enforce mandatory associations.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Many to many relationship in Entity Framework

From Dev

Entity Framework: One to Many relationship

From Dev

Entity Framework many to many relationship Delete

From Dev

Saving Many to Many relationship - Entity Framework

From Dev

Entity framework many-to-many relationship

From Dev

How many to many relationship in Entity Framework is working

From Dev

Update a Many to Many relationship using Entity Framework?

From Dev

Entity Framework duplicate entries in many to many relationship

From Dev

Updating many-to-many relationship entity framework

From Dev

Entity Framework Many TO Many Relationship with Primary Key

From Dev

Entity Framework with many to many relationship generetad tables

From Dev

Entity Framework Core Creating a Many to Many Relationship

From Dev

Entity Framework one-to-many and many-to-many relationship

From Dev

Entity Framework one-to-many and many-to-many relationship

From Dev

Eager Loading Many to Many relationship with an Association Entity - Entity Framework

From Dev

Entity Framework 4.2 One to many relationship

From Dev

One to many relationship in Entity Framework 6

From Dev

Entity Framework One-to-Many relationship with ordering

From Dev

Entity Framework - Trouble with one-to-many relationship

From Dev

entity framework 5, delete one to many relationship?

From Dev

Exception with Entity Framework 6, disconnected context and many-to-many relationship

From Dev

How to use Entity Framework 6 to update many-to-many relationship?

From Dev

Keep list of foreign keys in many-to-many Entity Framework relationship

From Dev

Mapping many to many relationship in entity framework code first

From Dev

Entity Framework not writing many to many relationship changes to the database

From Dev

Entity Framework "WHERE IN" style for Many-To-Many Relationship

From Dev

Query a many-to-many relationship with linq/Entity Framework. CodeFirst

From Dev

Add data to a many-to-many relationship using Entity Framework

From Dev

Entity Framework Delete Many to Many Relationship using stubs

Related Related

  1. 1

    Many to many relationship in Entity Framework

  2. 2

    Entity Framework: One to Many relationship

  3. 3

    Entity Framework many to many relationship Delete

  4. 4

    Saving Many to Many relationship - Entity Framework

  5. 5

    Entity framework many-to-many relationship

  6. 6

    How many to many relationship in Entity Framework is working

  7. 7

    Update a Many to Many relationship using Entity Framework?

  8. 8

    Entity Framework duplicate entries in many to many relationship

  9. 9

    Updating many-to-many relationship entity framework

  10. 10

    Entity Framework Many TO Many Relationship with Primary Key

  11. 11

    Entity Framework with many to many relationship generetad tables

  12. 12

    Entity Framework Core Creating a Many to Many Relationship

  13. 13

    Entity Framework one-to-many and many-to-many relationship

  14. 14

    Entity Framework one-to-many and many-to-many relationship

  15. 15

    Eager Loading Many to Many relationship with an Association Entity - Entity Framework

  16. 16

    Entity Framework 4.2 One to many relationship

  17. 17

    One to many relationship in Entity Framework 6

  18. 18

    Entity Framework One-to-Many relationship with ordering

  19. 19

    Entity Framework - Trouble with one-to-many relationship

  20. 20

    entity framework 5, delete one to many relationship?

  21. 21

    Exception with Entity Framework 6, disconnected context and many-to-many relationship

  22. 22

    How to use Entity Framework 6 to update many-to-many relationship?

  23. 23

    Keep list of foreign keys in many-to-many Entity Framework relationship

  24. 24

    Mapping many to many relationship in entity framework code first

  25. 25

    Entity Framework not writing many to many relationship changes to the database

  26. 26

    Entity Framework "WHERE IN" style for Many-To-Many Relationship

  27. 27

    Query a many-to-many relationship with linq/Entity Framework. CodeFirst

  28. 28

    Add data to a many-to-many relationship using Entity Framework

  29. 29

    Entity Framework Delete Many to Many Relationship using stubs

HotTag

Archive