Custom Properties |
Custom properties are user-defined additional data attributes of the domain objects. The custom properties support most of the same functionality which is supported by the system data attributes. The custom properties can be used for filtering queries, their values can be get and set, and they can be iterated.
Filtering:
//this will select all customers, which have the property "prop1" set to ("value1","descr1") var q = from c in transaction.Query<Customer>() where c["prop1"] == new CustomPropertyValue("value1", "descr1") select c; //this will select all customers, which have the property "prop1" set to ("value1") with empty description var q = from c in transaction.Query<Customer>() where c["prop1"] == new CustomPropertyValue("value1") select c;
Get and set value through normal attributes list:
Customer c = ...; CustomPropertyValue pv = c["custompropcode1"].Value as CustomPropertyValue; //get value string v = pv.Value; string d = pv.Description; Guid id = pv.ValueId; c["custompropcode1"].Value = new CustomPropertyValue("new", "descr", id);
Get and set value through custom properties list:
Customer c = ...; var pv = c.CustomProperties["custompropcode1"]; string v = pv.Value; string d = pv.Description; Guid id = pv.ValueId; c.CustomProperties["custompropcode1"] = new CustomPropertyValue("new value", "new descr", id);
Iterate all custom properties:
foreach(var propKeyValue in customer.CustomProperties) { Console.WriteLine("Property {0} = {1}", propKeyValue.Key.Name, propKeyValue.Value); }
Custom property values can be preloaded before accessing them in a loop. Actually it is strongly suggested that their values are preloaded before each loop, accessing any custom property.
invoices.Preload(i => i.CustomProperties); foreach (var invoice in invoices) { Console.WriteLine(invoice["export_type"]); }
For more information, see the types:
CustomPropertyDataAttribute