DEV Community

Discussion on: Going Against Conventional Wisdom: What's Your Unpopular Tech Opinion?

Collapse
 
aarone4 profile image
Aaron Reese

C# MVC.
If you have an Order entity with a virtual Icollection OrderLine and OederLine has a virtual Order, when you try to Order.Include(OrderLine) you get a cyclic dependency error. No s*it! It's a primary/foreign key relationship. It's supposed to be cyclic. Now I have to write a heap of boilerplate code. I need an entity model to represent my table. I also need a simpleViewModel for parent and child and a relationship ViewModel for the key relationship and have to access both I have to parentSimpleViewModel.Include(relationshipViewModel).thenInclude(childSimpleVieodel). I could just have called a view in SQL with the FOR JSON modifier and got back an API of the same shape, faster because it's at the DB level and reusable because it doesn't care whether the dB query comes from the API, from a query in Excel or PowerBI/SSRS. If performance is an issue the results can be cached or the JSON generated by another process in the database (e.g. the procedure that adds an order to the system)
Rant Over.