3

I have been struggling with peta poco and related classes and are getting the error "Couldn't find split point between PetaPocoProofOfConcept.Resource and PetaPocoProofOfConcept.BookingType".

My two classes are:

[TableName("Resource"), PrimaryKey("Id")]
public class Resource
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public long MinTimeSpan { get; set; }
    public long MaxTimeSpan { get; set; }
    public long FixedTimeSpan { get; set; }
    public DateTime ActiveStart { get; set; }
    public DateTime ActiveEnd { get; set; }
    public bool Active { get; set; }
    public BookingType BookingType { get; set; }
    public int StatusId { get; set; }
}

[TableName("BookingType"), PrimaryKey("Id")]
public class BookingType
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

I get the error when executing this line of code:

using (var connection = new SqlConnection(ConnectionString))
        {
            connection.Open();
            var resources = new Database(connection).Query<Resource, BookingType>("SELECT * FROM [Resource]").ToList();
        }

I have been reading some documentation but cant seem to find any answer of why this fails. Does anyone know?

Thanks :)

Diemauerdk
  • 5,238
  • 9
  • 40
  • 56

1 Answers1

3

That's not the way Petapoco multi mapping works. You can use that syntax in this way:

var posts = db.Fetch<post, author>(@"
        SELECT * FROM posts 
        LEFT JOIN authors ON posts.author = authors.id ORDER BY posts.id
        ");

This gives you two list with Posts and Authors.

If you want to perform more complex mappings (like your example), you need to write a callback like this:

var posts = db.Fetch<post, author, post>(
        (p,a)=> { p.author_obj = a; return p; },
        @"SELECT * FROM posts 
        LEFT JOIN authors ON posts.author = authors.id ORDER BY posts.id
        ");

More info on Petapoco Multi mapping

Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206