DapperLib / DapperLib/Dapper.Contrib

How to ignore some field with dapper

Open
#38 4 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.