Mis*_*sky 13 c# dapper dapper-contrib
我正在尝试使用Dapper.Contrib更新此表:
public class MyTable
{
public int ID { get; set; }
public int SomeColumn1 { get; set; }
public int SomeColumn2 { get; set; }
public int CreateUserID { get; set; }
public int UpdateUserID { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我不想更新CreateUserID列,因为它是一个更新方法,所以我想在调用Dapper - Update.Async(entity)方法时忽略此列.
我尝试使用[NotMapped]和[UpdateIgnore]属性,但没有帮助.
注意:我仍然希望在插入操作上传递此列,因此,[Computed]和[Write(false)]不合适.
有人可以帮我弄清楚在更新数据库中的表时如何忽略此列?
提前致谢.
嗯,只是不支持。这是相关问题,预计仅在 Dapper v2 中提供解决方案。您还可以检查源代码(非常简单)并看到更新的属性被搜索如下:
var allProperties = TypePropertiesCache(type);
keyProperties.AddRange(explicitKeyProperties);
var computedProperties = ComputedPropertiesCache(type);
var nonIdProps = allProperties.Except(keyProperties.Union(computedProperties)).ToList();
Run Code Online (Sandbox Code Playgroud)
因此,所有未用 Key\ExplicitKey\Compulated 标记且可写的属性都包含在内。同样的情况也会发生InsertAsync(除了属性ExplicitKey也包含在插入中,但您不能在您的情况下使用此属性,因为您的属性毕竟不是关键)。
因此,您必须等待实现,自己分叉并实现,或者只编写自己的UpdateAsync方法。从源代码可以看出,它非常简单,重新实现并不难。