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

  • SEARCH
  • Home
  • 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 8025639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:13:46+00:00 2026-06-04T23:13:46+00:00

I have a problem with MultiMaps in dapper trying to split on column that

  • 0

I have a problem with MultiMaps in dapper trying to split on column that contains NULL. Dapper seems not to instantiate object and my mapping function receives null instead of object.

Here’s my new test:

    class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public Category Category { get; set; }
    }
    class Category
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }
    public void TestMultiMapWithSplitWithNullValue()
    {
        var sql = @"select 1 as id, 'abc' as name, NULL as description, 'def' as name";
        var product = connection.Query<Product, Category, Product>(sql, (prod, cat) =>
        {
            prod.Category = cat;
            return prod;
        }, splitOn: "description").First();
        // assertions
        product.Id.IsEqualTo(1);
        product.Name.IsEqualTo("abc");
        product.Category.IsNotNull();
        product.Category.Id.IsEqualTo(0);
        product.Category.Name.IsEqualTo("def");
        product.Category.Description.IsNull();
    }

The line that fails is product.Category.IsNotNull(); due to the fact that cat passed to mapping function is null.

I’ve also added this method to Assert class:

public static void IsNotNull(this object obj)
{
    if (obj == null)
    {
        throw new ApplicationException("Expected not null");
    }
}
  • 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-04T23:13:47+00:00Added an answer on June 4, 2026 at 11:13 pm

    This is “by-design” though I would be ok to revisit it.

    In particular this behaviour is there to help with left joins. Take this for example:

    cnn.Query<Car,Driver>("select * from Cars c left join Drivers on c.Id = CarId",
       (c,d) => {c.Driver = d; return c;}) 
    

    Trouble is that if we allow a “blanket” creation of a Driver object, every Car is going to have a Driver even ones where the join failed.

    To work around we could scan the entire segment being split and ensure ALL values are NULL before mapping a NULL object. This will have a very minor perf impact on the multi mapper.

    To workaround for your case, you could insert a surrogate column:

    var sql = @"select 1 as id, 'abc' as name, '' as split, 
                NULL as description, 'def' as name";
        var product = connection.Query<Product, Category, Product>(sql, (prod, cat) =>
        {
            prod.Category = cat;
            return prod;
        }, splitOn: "split").First();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to start learning C++ and I have a problem. I'm trying to
I have problem with deserialize document to object using XmlSerializer class. Code my function
I have problem in my split Sentence function . The idea of ​​my function
I have problem in Listview onListItemClick() method. I am not getting the position of
I have problem with sending a object from my webservice. I have created a
I have a mapping of String id -> Object . Apart from merely having
I have problem with Activities navigation, searching works good. Activities hierarchy looks like that:
I have problem with this method in NLog library: NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(object state) It consume too
I have a problem where I need a .NET dictionary that supports multiple items
I have problem in some JavaScript that I am writing where the Switch statement

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.