开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜