Question: I'm trying to use PetaPoco to join more than four tables to populate an object of type A with five members of type B (very similiar to this question: https://stackoverflow.com/a/11275334/296296). From what I've read it would be possible to use this syntax:
var result = db.Query<Investment>(new System.Type[] { typeof(Investment), typeof(Person), typeof(Person), typeof(Person), typeof(Person), typeof(Person) }, null, sql, null).FirstOrDefault();
Where the sql is:
SELECT Investment.*, p1.*, p2.*, p3.*, p4.*, p5.* FROM Investment
INNER JOIN People p1 ON Investment.OwnerID = p1.Id
INNER JOIN People p2 ON Investment.ITOwnerID = p2.Id
INNER JOIN People p3 ON Investment.InformationOwnerId = p3.Id
INNER JOIN People p4 ON Investment.MaintenanceLeaderId = p4.Id
INNER JOIN People p5 ON Investment.MaintenanceLeaderITId = p5.Id
WHERE (Investment.Id = @0)
But it just gives me the following error:
Can't auto join Person as Investment has more than one property of type Person
Anyone who had the same problem or could help in any way?
Background:
I have the following (simplified) database tables:
Investment
--------------
Id
Name
OwnerId
ITOwnerId
InformationOwnerId
MaintenanceLeaderId
MaintenanceLeaderITId
People
--------------
Id
Name
The classes I would like to map these database tables to are:
Public class Investment {
public int Id
public string Name
public Person Owner
public Person ITOwner
public Person InformationOwner
public Person MaintenanceLeader
public Person MaintenanceLeaderIT
}
Public class Person {
public int Id
public string Name
}
In order to do so, I need to join the People table for every Person-type in the Investment class and map them to the corresponding property as instances of the type Person.