Can PetaPoco populate an object using a stored procedure with a join clause?

Posted by Mark Kadlec on Stack Overflow See other posts from Stack Overflow or by Mark Kadlec
Published on 2013-06-24T22:04:20Z Indexed on 2013/06/24 22:21 UTC
Read the original article Hit count: 696

Filed under:
|
|

I have a stored procedure that does something similar to:

SELECT a.TaskId, b.CompanyCode FROM task a JOIN company b ON b.CompanyId = a.CompanyId;

I have an object called TaskItem that has the TaskId and CompanyCode properties, but when I execute the following (which I would have assumed worked):

        var masterDatabase = new Database("MasterConnectionString");
        var s = PetaPoco.Sql.Builder.Append("EXEC spGetTasks @@numberOfTasks = @0", numberOfTasks);
        var tasks = masterDatabase.Query<Task>(s);

The problem is that the CompanyCode column does not exist in the task table, I did a trace and it seems that PetaPoco is trying to select all the properties from the task table and populating using the stored procedure.

How can I use PetaPoco to simply populate the list of task objects with the results of the stored procedure?

© Stack Overflow or respective owner

Related posts about stored-procedures

Related posts about orm