Is it possible to directly reference a many-to-many table using entity framework, code first

前端 未结 4 1518
春和景丽
春和景丽 2021-01-08 00:05

I am using the entity framework and modelling a many-to-many relationship.

I have created the relationship between the two entities using the fluent API (let\'s say

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-08 00:31

    Yes you can... If you use another Context.

    If you try to map more than one entity to the same table in the same Context then you will get the error. But if you put the two mappings in separate Contexts then there will be no issue. This way you can have one mapping that describes a many-many relationship with the joining table transparent as if there are only foreign keys in it... And you can have another mapping, with its own context, to expose the actual join table if you want to get at any properties of the relationship.

提交回复
热议问题