DapperLib / DapperLib/Dapper.Contrib
How to ignore some field with dapper
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
I have a "Product" api like this:
public Task<int> UpdateProduct(ProductRequest request)
{......}
public class ProductRequest
{
public int Id{get;set;}
public string Code{get;set;}
public string Name{get;set;}
public string Brand{get;set;}
......
}
the client sometimes want to update the name only. so the argument like this { Id:123, Name:"newName"}, But the argument received by the server becomes :
public class ProductRequest
{
public int Id //123
public string Code //null
public string Name //"newName"
public string Brand //null
......
}
// use sqlbuilder to generate sql text.
// etc.....
As you see, The server can't tell what needs to be updated, unless the fields has some value. the other null fields were confused, maby the client want to update it to NULL, or ignore it.
I don't want to seach it from database first and edit it and save it .. i think the search is redundant.
What should I do in this case?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file, test, or entry point is identified; begin by locating the ProductRequest handling and SQL-builder usage in the repository. Clarify how the update should distinguish omitted fields from explicit NULL values, then define tests showing both cases and the expected generated SQL before considering the work complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100