This resource explains how Computed
excludes a property (in an update only?).
Specifie the property should be excluded from update.
[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); }
Doesn't Write(false)
fulfill the same purpose though? What's the difference between [Computed]
and [Write(false)]
?
Edit:
I've just checked the resource linked in response to my question. It almost hits the nail on this! Could someone please confirm if both attributes perform the same operations, but are just worded in two different ways, as to give a better abstraction to their users?
Both
[Computed]
andWrite(false)
will ignore the property whileINSERT
as well asUPDATE
operations. So, both of them are same. You can use any one of it.Documentation says below:
About
Write
:As stated in first line in document above,
Write
handles "writeable" behavior. This should include bothINSERT
andUPDATE
.This can also be confirmed in source code here:
About
Computed
:Second line in document above is bit broad though.
Does that mean it can be the part of
INSERT
? No, it does not; it also cover both the actions. This can be observed with below code:With above code, you will observe that no matter which attribute you choose to decorate the property, it will neither be considered for
INSERT
nor forUPDATE
. So basically, both the attributes are playing same role.This can be further confirmed in Dapper.Tests.Contrib test project on github.
Looking at the comment and the value assigned to the property in above code, it makes clear that
Computed
should also ignore the property forINSERT
operation; it is expected result of the test.Why those two ways are provided for same purpose is not known. It causes confusion.
Following are some additional references:
Comment 1
Comment 2
Comment 3
I don't think
Computed
attribute has anything to do with Computed Columns as Dapper.Contrib support multiple RDBMS.