N for N Entity Framework

2

Dear, I'm trying to make a N to N relationship in the Entity Framework for the tables described below.

Atthemomentwhatishappeningisacyclicalredundancy,whereeverytimeIopenaGroup[x].GroupUser[x]atthispointIcaneithergobacktoGroupandfollowUser,andUserbacktoGroupUserandsoforGroup,isthisnormal?Wouldnotthatbeacyclicalredundancy?AmIdoingitwrong?Lookattheimagebelow.Thanksforthehelp.

    
asked by anonymous 16.12.2016 / 01:54

1 answer

1

This is normal behavior, since it is happening in navigation properties (which are references to objects). EF understands that navigation is bidirectional (user - > group / group - > user), and it just puts the elements pointing to the same reference. You can find out that the reference of each object is the same.

If you are going to use libraries like Automapper to dynamically copy the elements, you will have problems with overflow. But this can be solved in some ways: if you do not need to load related objects you can choose to disable LazyLoading. If you need related objects, you can use automapper settings to not delve more than a few levels in object references.

    
17.12.2016 / 01:47