小编hco*_*ode的帖子

Dapper自定义SqlMapper.TypeHandler解析方法未调用

我创建了一个SqlMapper.TypeHandler,将Customer对象映射到CreditAccount类,如下所示:

public class CustomerTypeHandler : SqlMapper.TypeHandler<Customer>
{
    public override Customer Parse(object value)
    {
        throw new NotImplementedException();
    }
    public override void SetValue(IDbDataParameter parameter, Customer 
    value)
    {
        throw new NotImplementedException();
    }
}

public class CreditAccount
{
    public int AccountId { get; set; }
    public Customer Customer{ get; set; }
}

public class Customer
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string MiddleName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

当我连接到数据库并调用一个sproc时,从不调用CustomerTypeHandler Parse方法,并且我的CreditAccount对象仅使用AccountId填充。Customer对象为空。

我这样称呼它:

    public async Task<CreditAccount> …
Run Code Online (Sandbox Code Playgroud)

dapper asp.net-core-2.2

5
推荐指数
1
解决办法
401
查看次数

标签 统计

asp.net-core-2.2 ×1

dapper ×1