Avoiding circular references in navigation properties
Hi guys š i have a question,
let's say i have two entities with a one to one relationship, and both have a navigation prop to the other,
when creating that entity what's the best way to avoid circular references?
6 Replies
creating it how? circular references are expected with bidirectional navigation properties and that is also how EF will populate them when requested from the database
that shouldn't matter unless you're trying to serialize your entities, which you shouldn't be
thx for the answer, can i ask you more about this? also with creating i meant for example creating the author, then creating the post and then assign them to each other, and then add them to db
you can just assign one side of the relationship and EF will figure it out when you call SaveChanges
how can i retrive this autor without getting a json circular exception for example?
by not using your entities as DTOs
create separate classes to represent your web requests and responses and map those to and from your entities
oh yea š sure dumb question sorry
š
š
well thx i figured it out š