Dapper Multi-Mapping第二个对象为空

时间:2018-02-04 20:34:17

标签: c# dapper

我正在尝试使用dapper进行多次映射,但我的lineitems没有返回任何值。订单按预期返回。

我只是没有获得LineItems的任何值,我已经在数据库/ sproc中验证了应该有数据。

我正在使用LineItems的界面....这可能是问题吗?

    public async Task<IEnumerable<IOrder>> ReadByCustomerIdAsync(int customerId)
    {
        _logger.Trace($"ReadByCustomerIdAsync(int customerId) started, customerId: {customerId}.");

        var result = await WithConnection(async c =>
            await c.QueryAsync<Order, LineItem, Order>("_Orders_LineItems_ReadByCustomerID", (order, lineitem) =>
             {
                 if (order.LineItems == null) order.LineItems = new List<LineItem>();
                 order.LineItems.ToList().Add(lineitem);
                 return order;
             }, new {  customerId }, commandType: CommandType.StoredProcedure, splitOn: "LineItemID"));

        if (!result.Any())
            _logger.Warn("ReadByCustomerIdAsync(int customerId) finished with no records.");
        else
            _logger.Trace($"ReadByCustomerIdAsync(int customerId) finished with {result.Count()} records."); 

        return result;
    }

public interface IOrder
{
    /// <summary>
    /// Gets or sets the billing address line1.
    /// </summary>
    /// <value>The billing address line1.</value>
    string BillingAddressLine1 { get; set; }

    /// <summary>
    /// Gets or sets the billing address line2.
    /// </summary>
    /// <value>The billing address line2.</value>
    string BillingAddressLine2 { get; set; }

    /// <summary>
    /// Gets or sets the billing city.
    /// </summary>
    /// <value>The billing city.</value>
    string BillingCity { get; set; }

    //code left out...
    IEnumerable<ILineItem> LineItems { get; set; }
}

0 个答案:

没有答案