在Dapper(http://code.google.com/p/dapper-dot-net/)中,有没有办法忽略模型类中的属性,即使用Insert
扩展方法时?我的模型类有一组计算属性,这些属性不会保存在关联的表中.
谢谢.佩德罗
此资源解释了如何Computed
排除属性(仅在更新中?)。
指定应从更新中排除该属性。
Run Code Online (Sandbox Code Playgroud)[Table("Invoice")] public class InvoiceContrib { [Key] public int InvoiceID { get; set; } public string Code { get; set; } public InvoiceKind Kind { get; set; } [Write(false)] [Computed] public string FakeProperty { get; set; } } using (var connection = My.ConnectionFactory()) { connection.Open(); var invoices = connection.GetAll<InvoiceContrib>().ToList(); // The FakeProperty is skipped invoices.ForEach(x => x.FakeProperty += "z"); var isSuccess = connection.Update(invoices); }
不Write(false)
达到同样的目的吗?[Computed]
和 和有[Write(false)]
什么区别?
编辑:
我刚刚检查了为回答我的问题而链接的资源。它几乎一针见血!有人可以确认这两个属性是否执行相同的操作,但只是以两种不同的方式表达,以便为用户提供更好的抽象?