oceanicwang / dapper-dot-net

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

Multimapping with nested objects and having ID into first column. #34

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a table and stored procedure (SpGetAllPersons) which returns below 
schema:

PersonGUID, FirstName, LastName, Age, Sex, Address

2.  Create model as per below:

Class Person
{
int PersonGUID { get; set; } 
Name name { get; set; }
int Age { get; set; }
bool Sex { get; set; }
string Address { get; set; }
}

3.  Write a dapper query to populate fields.

List<Person> persons = DbConn.Query<Name,Person,Person>
  ("SpGetAllPersons",
     (name,person) => {person.Name = name; return person;} 
     commandType: CommandType.StoredProcedure, 
     splitOn: "PersonGUID, Age, Sex, Address").ToList();

What is the expected output? What do you see instead?
Expected Output : All the values should be prefilled correctly into Model.
Actual Output : All the IDs were 0.

What version of the product are you using? On what operating system?
Windows XP Sp3, .NET 4.0, SQL Mapper version: acacfa6a6d59

Please provide any additional information below.
I debugged the code and found below:

Line 496: There is a function like below:

Func<int> nextSplit = () =>
                        {
                            var currentSplit = splits[splitIndex];
                            if (splits.Length > splitIndex + 1)
                            {
                                splitIndex++;
                            }
                            int pos;
                            for (pos = current + 1; pos < reader.FieldCount; pos++)
                            {
                                // some people like ID some id ... assuming case insensitive splits for now
                                if (splitOn == "*" || string.Equals(reader.GetName(pos), currentSplit, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    break;
                                }
                            }
                            current = pos;
                            return pos;
                        };

Here Pos starts from 1 instead of 0 so it will always skip the 1st column of 
Reader.  I removed 1 and Dapper started populating all the ID values correctly.

Original issue reported on code.google.com by RSBak...@gmail.com on 7 Jun 2011 at 11:27

GoogleCodeExporter commented 8 years ago
I figured out the issue here.  The columns which are part of Nested object, 
should be the leading ones on Resultset coming back from Database and than 
Split on the 1st starting column.

It took me while to figure this out.  We need to keep + 1 in above for loop.

Dappper badly requires some API Guide or Documentation where all these info are 
readily available.

Original comment by RSBak...@gmail.com on 8 Jun 2011 at 1:17

GoogleCodeExporter commented 8 years ago
You should also post the SQL for your stored proc. It makes it difficult to 
investigate without seeing this.

Original comment by b...@planetcloud.co.uk on 11 Jun 2011 at 9:47

GoogleCodeExporter commented 8 years ago
I improved the error message for the multi mapper ... this should cover this. 

Original comment by sam.saff...@gmail.com on 13 Jul 2011 at 7:22