DapperLib / DapperLib/Dapper

MultiMap does not return null object in left-outer-join if splitting on a surrogate key that is not a property on the target object.

Open
#222 4 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-investigation
Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

This issue is really for left-outer-joins where we would expect a null object if there is no match. Unfortunately, the object is not coming back null even though the 'spliton' column is null.

Class structure
public class Post[PostID,Name,CategoryID?] //category is optional (left-outer joined)
public class Category[CategoryID,Name]

Query using aliases to split on 'id'

SELECT p.*, c.CategoryID AS id, //surrogate key helps mark the split...will be null if no matching category c.* FROM Posts p LEFT OUTER JOIN Categories c ON c.CategoryID = p.CategoryID

If there is no category, the expected behavior is that because the 'id' column is null the entire object would be null. However, because 'id' does not exist as a property on the Category object we get an instantiated object.

Note that we're splitting this way because p.* already has CategoryID so we can't explicitly split on that.

I've gone through the source code for a bit but it's a little beyond me (for now at least). I'll keep trying to pinpoint why that is happening and get a test in there to prove it.

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

Start at Dapper's MultiMap handling for the splitOn alias in the shown left-outer-join query, and reproduce the case where the aliased id is null but is not a property on Category. Trace how the split column determines whether the target object is created. Done means an unmatched Category maps to null, with a regression test covering this query shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.