Interface IDataObject
Data object interface
Namespace: XData
Assembly: XData.docfx.dll
Syntax
[JsonConverter(typeof(JsonDataObjectConverter<IDataObject>))]
public interface IDataObject : ISqlObject
Remarks
Mapping domain object to database
WARNING! Data object mapping requires DataObjectAttribute!
Hint: Use DataTableAttribute, SubqueryAttribute and InnerViewAttribute to map data object to data sources
Hint: Use FilterAttribute's specific successor to link data sources and apply filters to data
Hint: Use ExternalLinkAttribute to declare master/slave relations between repositories
Hint: Use Lob to map binary fields
[Property("scan", "SC", Flags = DataPropertyFlag.OuterFlag)]
public Lob Scan { get; set; }
Hint: Use Xml to map Xml fields
[Property("source", "SR", Flags = DataPropertyFlag.OuterFlag)]
public Xml Source { get; set; }
Hint: Use Link<TVal, TSrc> to map data link
[Property("name", "S"),
DictionaryProperty("Name", "DocState"),
DictionaryProperty("Code", "DocStateCode")]
public Link<string, DocState> DocState { get; set; }
Hint: Use ColumnAttribute to map data without declaring property (for example to declare Id)
[DataObject("S"),
DataTable("T_DOC_STATE", "S"),
Column("DocStateId", "doc_state_id", typeof(long?), "S", Flags = DataPropertyFlag.Id)]
Hint: Use PropertyExpressionAttribute or ColumnExpressionAttribute to use SQL expression or subquery as property (or mapped column) data source
[Property("doc_amount"),
PropertyExpression("A", DataExpressionType.SubQuery, DbType.Decimal, ExprSize = 17, ExprScale = 5)]
public double? DocAmount { get { return this.GetProperty(() => DocAmount); } }
Hint: Use PropertyDefaultAttribute or ColumnDefaultAttribute to set default value generation rule to property (or mapped column)
[Property("doc_date", "D"),
PropertyDefault(DefaultType.CurrentDate)]
public DateTime? DocDate { get; set; }
Hint: Use ReferenceAttribute to use inner view property in parent data object
[PropertyLink("HistoryDate", "H")]
public DateTime? DocLastChange { get { return this.GetProperty(() => DocLastChange); } }
Hint: Declare readonly fields as
[PropertyLink("HistoryDate", "H")]
public DateTime? DocLastChange { get { return this.GetProperty(() => DocLastChange); } }
Hint: Declare custom logic functions (see IDataLogic<T> and Execute<T>(ICollection<T>, String, IDictionary<String, Action<Byte[]>>, IDictionary<String, Func<Byte[], Byte[]>>)) as
//generate unique action key and use it for mark it realization in IDataLogic<Invoice>
[CustomAction("{ab12d6f0-69d0-4997-bb0b-5f5f7c0581d1}")]
public static CustomLogic<Invoice> TestCustomLogic;
//using
obj.Execute(() => Invoice.TestCustomLogic);
Hint: Variables can be used as temporary values storage
// store
obj.GetRepository().Variables.Add("SomeName", "SomeValue");
// and somewhere you can get it
var something = obj.GetRepository().Variables["SomeName"];
Hint: HierarchyAttribute can be used to fill and maintain hierarchy tables automatically
// Table T_TEST has parent_id field tree linked to test_id (T_TEST's pk)
// Table L_TEST has two fields parent_id and child_id all linked to T_TEST.test_id
// Table L_TEST contains all subtree relations inside T_TEST
// For example: for T_TEST (test_id, parent_id): (1, null) : (2, 1) : (3, 2)
// L_TEST will contain (parent_id, child_id): (1, 1) : (1, 2) : (1, 3) : (2, 2) : (2, 3) : (3, 3)
[DataObject("T"),
DataTable("T_TEST", "T"),
Hierarchy("T", "L_TEST", "parent_id", "parent_id", "child_id"),
Column("TestId", "test_id", typeof(long?), "T", Flags = DataPropertyFlag.Id)]
Examples
[DataObject("T"),
DataTable("T_DOC_TYPE", "T"),
Column("DocTypeId", "doc_type_id", typeof(long?), "T", Flags = DataPropertyFlag.Id)]
public class DocType : IDataObject {
[Property("name", "T")]
public string Name { get; set; }
[Property("code", "T")]
public string Code { get; set; }
}