Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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. #222

Open
BlackjacketMack opened this issue Dec 16, 2014 · 3 comments

Comments

@BlackjacketMack
Copy link
Contributor

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.

@ajbeaven
Copy link

+1

var animals = Connection.Query<Animal, Owner, Animal>(@"
    SELECT Animal.*, NULL as split, Owner.*
    FROM Animal
    LEFT JOIN Owner ON Animal.OwnerId = Owner.OwnerId", (a, o) => { a.Owner = o; return a; }, splitOn: "split").ToList();

I would expect Owner would be NULL in this case.

@jmzagorski
Copy link

any update on this or workarounds? I am using the Read method from this request #308. Thanks.

@paveldayneko
Copy link

Is there any update regarding this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants