【发布时间】:2021-03-17 19:22:27
【问题描述】:
public class Customer
{
[ExplicitKey]
public int Id { get; set; }
[Write(false)]
public string FullName { get; set; }
public string Username { get; set; }
public string Email { get; set; }
public string EmailToRevalidate { get; set; }
public string SystemName { get; set; }
public int BillingAddress_Id { get; set; }
..................
..................
public int Add(Customer customer)
{
using (IDbConnection conn = Connection)
{
var result = conn.InsertAsync(customer).Result; // need to fix this it is return 0 because of the explicitkey attribue on ID.
return result;
}
}
我希望 Add() 方法返回实际输入的 Id,即在客户对象中。否则我想返回整个对象。但我需要知道插入是否成功。
有没有办法检查 InsertAsync() Success = true 吗??
【问题讨论】:
-
如果您决定退回到 Dapper(绕过 Contrib),this 可能会有所帮助。是在 MS Access 的上下文中,但基本原理还是一样的。