我创建了一个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)