N for N Entity Framework

Asked

Viewed 198 times

2

Dear, I am trying to carry out a relationship N to N in the Entity Framework for the tables described below.

inserir a descrição da imagem aqui

At the moment what is happening is a cyclical redundancy, where every time I open a Group[x]. Groupuser[x] at this point I can either go back to Group or go to User, and go back to Groupuser and so on to Group, is that normal? Wouldn’t that be cyclic redundancy? Am I doing it wrong? Look at the image below. I appreciate the help.

inserir a descrição da imagem aqui

1 answer

1


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

If you’re going to use libraries like Automapper to dynamically copy the elements, you’ll have overflow problems. But this can be solved in a few ways: if you don’t need to load the related objects you can choose to disable Lazyloading. If you need the related objects, you can use the automapper settings not to go deeper than some levels in object references.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.