public TestModel() : base("test.test_model") { IsVersioned = false; Fields.Chars("name").SetLabel("姓名").SetSize(64).Required(); Fields.Chars("address").SetLabel("地址").SetSize(200).Required(); Fields.Integer("field1").SetLabel("数1"); Fields.Integer("field2").SetLabel("数2"); Fields.Integer("field3").SetLabel("数3").SetValueGetter(this.GetField3); Fields.BigInteger("big_int_field").SetLabel("Bit Int Field"); Fields.Boolean("boolean_field").SetLabel("Boolean Field").Required().SetDefaultValueGetter(s => true); Fields.Text("text_field").SetLabel("Text Field"); Fields.Double("double_field").SetLabel("Double Field"); Fields.Decimal("money_field").SetLabel("Decimal Field"); Fields.Enumeration("enum_field", new Dictionary <string, string>() { { "state1", "State 1" }, { "state2", "State2" } }) .SetLabel("Enumeration Field"); Fields.Binary("binary_field").SetLabel("Binary Field"); Fields.Reference("reference_field").SetLabel("Reference Field").SetOptions( new Dictionary <string, string>() { { "test.master", "Master Model" }, { "test.child", "Child Model" }, }); }
private void AddInternalFields() { Debug.Assert(this.Fields.ContainsKey(IdFieldName)); //只有非继承的模型才添加内置字段 if (this.AutoMigration) { Fields.DateTime(CreatedTimeFieldName).SetLabel("Created") .NotRequired().SetDefaultValueGetter(ctx => DateTime.Now).Readonly(); Fields.DateTime(UpdatedTimeFieldName).SetLabel("Last Modified") .NotRequired().SetDefaultValueGetter(ctx => DateTime.Now); Fields.ManyToOne(CreatedUserFieldName, "core.user").SetLabel("Creator") .NotRequired().Readonly() .SetDefaultValueGetter(ctx => ctx.UserSession.UserId > 0 ? (object)ctx.UserSession.UserId : null); Fields.ManyToOne(UpdatedUserFieldName, "core.user").SetLabel("Modifier") .NotRequired() .SetDefaultValueGetter(ctx => ctx.UserSession.UserId > 0 ? (object)ctx.UserSession.UserId : null); if (this.Hierarchy) { this.AddHierarchyInternalFields(); } } if (this.IsVersioned) { Fields.BigInteger(VersionFieldName).Required() .SetLabel("Row Version").SetDefaultValueGetter(v => 0); } }
public AttachmentEntity() : base("core.attachment") { Fields.Chars("name").WithLabel("Name"); Fields.Chars("res_name").WithLabel("Related Resource"); Fields.BigInteger("res_id").WithLabel("Related Resource ID."); Fields.Text("description").WithLabel("Description"); Fields.Chars("link").WithLabel("Link"); Fields.Binary("content").WithLabel("Content"); Fields.ManyToOne("organization", "core.organization").WithLabel("Organization"); }
public EntityDataEntity() : base(entityName) { this.IsVersioned = false; Fields.Chars("name").WithLabel("Key").WithRequired().WithSize(128); Fields.Chars("module").WithLabel("Module").WithRequired().WithSize(64); Fields.Chars("entity").WithLabel("Entity").WithRequired().WithSize(64); Fields.BigInteger("ref_id").WithLabel("Referenced ID").WithRequired(); Fields.Text("value").WithLabel("Value"); }
public AuditLogModel() : base(ModelName) { Fields.ManyToOne("user", "core.user").SetLabel("User"); Fields.Boolean("marked").SetLabel("Marked As Read") .Required().SetDefaultValueGetter(ctx => false); Fields.Chars("resource").SetLabel("Resource Name").SetSize(64).Required(); Fields.BigInteger("resource_id").SetLabel("Resource ID").Required(); Fields.Chars("description").SetLabel("Description") .Required().SetSize(256); }
public ModelDataModel() : base(ModelName) { this.IsVersioned = false; Fields.Chars("name").SetLabel("Key").Required().SetSize(128); Fields.Chars("module").SetLabel("Module").Required().SetSize(64); Fields.Chars("model").SetLabel("Model").Required().SetSize(64); Fields.BigInteger("ref_id").SetLabel("Referenced ID").Required(); Fields.Text("value").SetLabel("Value"); }
private void AddHierarchyInternalFields() { Debug.Assert(this.Hierarchy); Debug.Assert(!this.Fields.ContainsKey(LeftFieldName)); Debug.Assert(!this.Fields.ContainsKey(RightFieldName)); Fields.BigInteger(LeftFieldName).SetLabel("Left Value") .Required().SetDefaultValueGetter(ctx => - 1); Fields.BigInteger(RightFieldName).SetLabel("Right Value") .Required().SetDefaultValueGetter(ctx => - 1); //这里通过 SQL 查询返回 if (!Fields.ContainsKey(ParentFieldName)) { Fields.ManyToOne(ParentFieldName, this.Name) .SetLabel("Parent").NotRequired().OnDelete(OnDeleteAction.SetNull); } Fields.OneToMany(ChildrenFieldName, this.Name, ParentFieldName) .SetLabel("Children") .SetValueGetter((scope, ids) => { var result = new Dictionary <long, object>(ids.Length); foreach (var id in ids) { var children = this.GetChildrenIDs(scope.DataContext, id); result.Add(id, children); } return(result); }); Fields.OneToMany(DescendantsFieldName, this.Name, ParentFieldName) .SetLabel("Descendants") .SetValueGetter((scope, ids) => { var result = new Dictionary <long, object>(ids.Length); foreach (var id in ids) { var children = this.GetDescendantIDs(scope.DataContext, id); result.Add(id, children); } return(result); }); }
public PropertyEntity() : base("core.property") { Fields.Chars("name").WithSize(64).WithLabel("Name").WithRequired(); Fields.Enumeration("type", new Dictionary <string, string>() { { "integer", "Integer" }, { "double", "Double" }, { "binary", "Binary" }, { "datetime", "Date Time" }, { "text", "Text" }, }).WithLabel("Type").WithRequired(); Fields.Binary("value_binary").WithNotReadonly().WithLabel("Binary Value"); Fields.Double("value_float").WithNotReadonly().WithLabel("Double Float Value"); Fields.BigInteger("value_integer").WithNotReadonly().WithLabel("Integer Value"); Fields.DateTime("value_datetime").WithNotReadonly().WithLabel("Datetime Value"); Fields.Text("value_text").WithNotReadonly().WithLabel("Text Value"); Fields.ManyToOne("organization", "core.organization").WithLabel("Organization"); }
public TestEntity() : base("test.test_entity") { IsVersioned = false; Fields.Chars("name").WithLabel("姓名").WithSize(64).WithRequired(); Fields.Chars("address").WithLabel("地址").WithSize(200).WithRequired(); Fields.Integer("field1").WithLabel("数1"); Fields.Integer("field2").WithLabel("数2"); Fields.Integer("field3").WithLabel("数3").WithValueGetter(this.GetField3); Fields.BigInteger("big_int_field").WithLabel("Bit Int Field"); Fields.Boolean("boolean_field").WithLabel("Boolean Field").WithRequired().WithDefaultValueGetter(s => true); Fields.Text("text_field").WithLabel("Text Field"); Fields.Xml("xml_field").WithLabel("XML Field"); Fields.Double("double_field").WithLabel("Double Field"); Fields.Decimal("money_field").WithLabel("Decimal Field"); Fields.Date("date_field").WithLabel("Date Field"); Fields.Time("time_field").WithLabel("Time Field"); Fields.DateTime("datetime_field").WithLabel("DateTime Field"); Fields.Enumeration("enum_field", new Dictionary <string, string>() { { "state1", "State 1" }, { "state2", "State2" } }) .WithLabel("Enumeration Field"); Fields.Binary("binary_field").WithLabel("Binary Field"); Fields.Reference("reference_field").WithLabel("Reference Field").WithOptions( new Dictionary <string, string>() { { "test.master", "Master Entity" }, { "test.child", "Child Entity" }, }); }