Reputation: 330
I have this object called Event, and event has some other linked tables.
[PetaPoco.ResultColumn]
public Models.User Presenter { get; set; }
Petapoco does a wonderful job by fetching my objects when I use:
evt = db.Fetch<Models.Event, Models.User>(";EXEC GetEventDetails @id", new { id = id });
This brings me the event, with the presenter data.
But the problem is that I also have a column being generated in my query 'Available seats' This column is linked to the object as:
[PetaPoco.ResultColumn]
public string AvailableSeats { get; set; }
The problem is: when I use the db.Fetch, Available seats is null. My solution now is:
evt = db.Fetch<Models.Event>(";EXEC GetEventDetails @id", new { id = id })[0];
evt.Presenter = db.FirstOrDefault<Models.User>("WHERE id=" + evt.PresenterId);
but I don't really like this. it should be all in one line of code.
Is this a petapoco bug, or am I doing something wrong there?
Upvotes: 2
Views: 1266
Reputation: 39413
My guess (without looking under the covers) it's that PetaPoco only fill the corresponding table fields when you do a multi-join, because it need to guess witch field match with each table.
My recommendation for these type of joins is to have a ViewModel object only with the properties needed. This is more clear and faster and only will take a few more minutes.
Upvotes: 1