1

If i have a Person class which have Dog class property :

public class Person{
 public string Name {get;set;}
 public Dog Doggie {get;set;}
}

On a single SP call i want to populate both dog object and person object, but i cant figure out how to do that.

CREATE PROCEDURE Test
 AS
BEGIN
    SET NOCOUNT ON;

    -- Insert statements for procedure here
      SELECT 
        Name                = p.Person_Name,
        Doggie.Name (This fails) = d.Dog_Name

      FROM My fancy join......
END
GO



  public Person GetByUid(Guid uid)
    {
        Person personToReturn;

        using (var connection = this.connectionFactory.GetOpenConnection())
        {
            try
            {
                personToReturn= connection.Query<Person>("ProcedureName",
                    new {  personUid = uid },
                    commandType: CommandType.StoredProcedure).Single();
            }
            catch ()
            {
                return null;
            }

        }

    return personToReturn;
}

Is it possible?

Timsen
  • 4,066
  • 10
  • 59
  • 117
  • You need to show us how you are invoking the stored procedure, and how you are mapping its returns to your Person class properties. – RBarryYoung Feb 11 '15 at 20:42

1 Answers1

2

Use the QueryMultiple, and write 2 SELECT statements in ONE stored procedure.

Here are some helper links.

Dapper.NET and stored proc with multiple result sets

Multiple SQL statements in one roundtrip using Dapper.NET

Community
  • 1
  • 1
granadaCoder
  • 26,328
  • 10
  • 113
  • 146