ibizq / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Multi mapping where split on column is in class definition but not result set #177

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Having a property with the same name as the splitOn key that is not returned in 
the sql result set causes issue with multimapping. The following test hopefully 
illustrates:

public void TestMultiMappingWithNonReturnedProperty()
        {
            var sql = @"select 
                            1 as PostId, 'Title' as Title,
                            2 as BlogId, 'Blog' as Title";
            var postWithBlog = connection.Query<Post_DupeProp, Blog_DupeProp, Post_DupeProp>(sql,
                (p, b) =>
                {
                    p.Blog = b;
                    return p;
                }, splitOn: "BlogId").First();

            postWithBlog.PostId.IsEqualTo(1);
            postWithBlog.Title.IsEqualTo("Title");
            postWithBlog.Blog.BlogId.IsEqualTo(2);
            postWithBlog.Blog.Title.IsEqualTo("Blog");
        }

        class Post_DupeProp
        {
            public int PostId { get; set; }
            public string Title { get; set; }
            public int BlogId { get; set; }
            public Blog_DupeProp Blog { get; set; } 
        }

        class Blog_DupeProp
        {
            public int BlogId { get; set; }
            public string Title { get; set; }
        }

In this case the current behaviour attempts to split on the BlogId property of 
the Post_DupeProp instead of on the key in the Blog_DupeProp.

I've forked, fixed and will shortly issue a pull request on GitHub.

For reference: https://github.com/Polylytics/dapper-dot-net

Original issue reported on code.google.com by markj...@googlemail.com on 2 Jun 2014 at 1:00

GoogleCodeExporter commented 9 years ago
fixed via https://github.com/StackExchange/dapper-dot-net/pull/123

Original comment by marc.gravell on 2 Jun 2014 at 1:42