Is it possible to remove a many-to-many relationship without using `Include` in EF Core?
Let's say there is a many-to-many relationship between
A
and B
, and an entity a
of type A
with an ID of 1 is related to an entity b
of type B
with an ID of 2. Is it possible to remove this relationship without using context.A.Include(a => a.Bs)...
or an explicit join table?7 Replies
What do you mean "remove it"?
.Include
certainly does not remove any relationshipsBasically I want to remove a row in the join table where the
AId
column is 1 and the BId
column is 2
The only way I know is to use Include
to populate the collection navigation property of A
first, then remove the B
instance with an ID of 2 from it, then call SaveChanges
or
would work
I don't want to use an explicit join table
Tough
You should be able to
There should be shadow properties for this stuff
And you can get the table by name
Or from a relationship
If you have a property referencing the
JoinTable
, sure
But that would require that JoinTable
to exist in code
Ergo, explicit join table one way or another