henkmollema / Dommel

CRUD operations with Dapper made simple.
MIT License
611 stars 99 forks source link

Support for 2 level nest mapping #242

Closed c-Cyril-l closed 3 years ago

c-Cyril-l commented 3 years ago

First of all thanks for such a great framework.

I'm struggling to map nested objects.

[Table (nameof(Category))]
public class Category
{
    public int Id { get; set; }
    public string Name { get; set; }
}
[Table(nameof(Book))]
public class Book
{
    public int Id { get; set; }
    public string Name { get; set; }

    public int CategoryId { get; set; }
    public Category Category { get; set; }
}
[Table(nameof(Order))]
public class Order
{
    public int Id { get; set; }
    public int Unit { get; set; }
    public int Price { get; set; }

    public int BookId { get; set; }
    public Book Book { get; set; }
}

The Goal is getting each order with its book and the book with its category.

What I've tried:

GetAllAsync<Order, Book, Category, Order>(
                (order, book, category, supplier) =>
                {
                    order.Book = book;
                    order.Book.Category = category;
                    return order;
                });

Issue :

System.InvalidOperationException: 'Could not resolve foreign key property. Source type 'Order'; including type: 'Category'.'

Why do category know about Order ?

Am I doing something wrong here ? or there is no support for this type of mapping yet ?

Best Regards

henkmollema commented 3 years ago

This mapping is not supported in Dommel. The aim of Dommel is to keep it simple which means it's not as feature-rich as a full blown ORM such as Entity Framework.