Dapper Contrib Computed Use Data Annotation With Computed Column
Description
The Computed attribute specifies that the property should be excluded from the update.
- You can use
Computedcolumns in the database and decorate your entity with theComputedattribute to prevent updating its value to the table. - The
Computedattribute allows you to specify that a property should be calculated based on the values of other properties.
The following example shows how to use the Computed attribute on a property in which you don't want to update its value in the database table.
// @nuget: Dapper.Contrib using Dapper.Contrib.Extensions; [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); }
ZZZ Projects