开发者

MVC: what to pass in repository methods - entity or values?

开发者 https://www.devze.com 2023-02-21 05:23 出处:网络
I have some repository methods which can update an whole entity or its parts (for example, when a user approves an invitation all i need to update is only \"Approved\" field).

I have some repository methods which can update an whole entity or its parts (for example, when a user approves an invitation all i need to update is only "Approved" field). What is the best practice for passing parameters in such repo methods? Should i pass a whole entity "Invitation" and use only one field for updation or should i pass only ent开发者_Go百科ity's ID and the "Approved" value? Thanks.


I recommend passing the entity itself if you already have it. If you've already queried for it why make the repository query again?

The only time I pass an id around is in situations I don't already have the object, but that's pretty rare, as once I get the ID in the controller I tend to query for the object right there.

0

精彩评论

暂无评论...
验证码 换一张
取 消