Do not update a certain property on Update method with dapper extensions

dapper dapper-extensions

Question

I know I can use the pure dapper to build my update string with only the properties I want to update (whitelist).

What I want is to keep the ORM style of dapper extensions:

con.Update<Person>(person);

I want that some properties of person are not updated (blacklist)

How can I exlude properties from being updated running the .Update extension method?

Do you maybe know of a better .Update extension in the dapper style? (Then I dont have to

write it ;-)

Popular Answer

You can try using a separate class for that (for example, a descendant of Person or a wrapper around it with a separate mapper that ignores the property).

But that is way too ugly to be a good solution.

DapperExtensions currently are way too straightforward for anything except explicit CRUD tasks. I had to develop a custom mapper just to add System.ComponentModel annotations support, which seems ridiculous for 2015.

But adding a new UpdatePartial extension method looks like a nice idea.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why