Let’s say we have two tables with a many-to-many relationship:
public class Left{ /**/ }
public class Right{ /**/ }
public class LeftRight{ /**/ }
is the following sufficient to unhook these records (ignore the possibility of more than one relationship or no relationship defined)?
public void Unhook(Left left, Right right){
var relation = from x in Left.LeftRights where x.Right == right;
left.LeftRrights.Remove(relation.First());
Db.SubmitChanges();
}
Or do I have to do it on both parts? What’s required here?
Here is a ‘little’ extension method I wrote to simplify this problem:
It could probably be improved, but it has served me well 🙂
Example:
Algorithm description:
Suppose A and B is many-to-many relationship, where AB would be the intermediary table.
This will give you:
You now have an object of A, that reference many B’s via AB.
I would like to improve this by using Expression instead, so I could ‘template’ the method better, but it would work the same.