C
C#2mo ago
FraznoFire

Return Value on Entity Modification

Hi everyone, I'm creating a class library that contains my entity framework models and surrounding business logic for my project. I am creating a method for modifying one property of my entity. I am wondering if it is best practice to have this method return the entire object, a bool for success/fail, the changed value, or nothing. My thinking is that since the method is being passed a reference to the entity stored in the database, I shouldn't have to return the full entity as the change has been saved, but I just don't know what sort of standard to apply in my code and if it will have any negative cosequences in the future of the codebase.
3 Replies
Anton
Anton2mo ago
I depends what the frontend needs that should be the driver of such decisions either one is fine
FraznoFire
FraznoFire2mo ago
oh ok, I thought that if my code was unnecssarily returning object references it might cause a memory leak or performance issue Come to think of it, would it be better to write the property modification code into the “get/set” methods of the property? Or at least in the class itself? That way nothing in the code base can incorrectly modify the values outside of business logic?
Anton
Anton2mo ago
if it's a domain model, maybe. if it's a database model, definitely not
Want results from more Discord servers?
Add your server