Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9011871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:51:23+00:00 2026-06-16T02:51:23+00:00

I know it’s kind of the wrong thing to do, but I’m dealing with

  • 0

I know it’s kind of the wrong thing to do, but I’m dealing with a legacy codebase that has NULLS when it means empty strings and vice versa.

I can’t immediately see how it is possible, but is it possible to get (or modifiy dapper so it will) return an empty string instead of a null string when mapping back from the database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:51:24+00:00Added an answer on June 16, 2026 at 2:51 am

    Dapper doesn’t call any setter when it sees a null, so options might include:

    • set the default value to "" in the constructor
    • check for null in the accessor

    So:

    public class SomeDto
    {
        public SomeDto()
        {
            Name = "";
        }
        public string Name {get;set;}
    }
    

    or:

    public class SomeDto
    {
        private string name;
        public string Name { get {return name ?? "";} set {name = value;} }
    }
    

    However, this only applies to reading values; I can’t think of a nice way to get dapper to turn "" into null when passing the dto in as the parameter object; options include:

    • creating an anon-type, substituting "" to null (perhaps write a string NullIfBlank(this string s) extension method)
    • having a shim property on the type that returns null in place of "", and have your database query bind to @NameOrNull rather than @Name
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
I know that this has been discussed thousand times but I still cannot figure
I know that there has been one question about this but it is not
I know that if port 443 is open that means the remote host supports
I know that this isn't exactly normalised, but bringing all of the localised data
I know most commercial games development is done in assembly or C/C++ but has
I know, asking this is a funny thing. But i am new to SQL
I know this has been asked but I am unable to fix it For
I know this is a very basic question but sometimes it happens that you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.