Petapoco - 找不到分割点

Petapoco - Couldn't find split point

我一直在与 peta poco 和相关 类 作斗争,并收到错误 "Couldn't find split point between PetaPocoProofOfConcept.Resource and PetaPocoProofOfConcept.BookingType"。

我的两个类是:

[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; }
}

执行这行代码时出现错误:

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

我一直在阅读一些文档,但似乎无法找到失败原因的任何答案。有人知道吗?

谢谢:)

这不是 Petapoco 多重映射的工作方式。 您可以通过这种方式使用该语法:

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

这为您提供了两个包含帖子和作者的列表。

如果你想执行更复杂的映射(比如你的例子),你需要像这样写一个回调:

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