Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dapper - pass whole entity as query parameter or anonymous object

Tags:

c#

dapper

I want to know if there are any recommendations with query parameters

Is it ok to pass the whole object or is it better to create a lightweight anonymous object with properties I need?

Query<SomeObj>("Select * from SomeObjs where Id = @Id", someObj);

or

Query<SomeObj>("Select * from SomeObjs where Id = @Id", new {someObj.Id});

Are there any performance or memory implications for one over other?

like image 828
Mayank Avatar asked Feb 17 '26 04:02

Mayank


1 Answers

For how Dapper works, by creating and caching the mapping code on the fly at the first use, it doesn't really matter.

like image 164
mauridb Avatar answered Feb 19 '26 18:02

mauridb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!