public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { base.Apply(context, attribute, member); var da = (DisplayNameAttribute)attribute; member.DisplayName = da.DisplayName; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { if (!string.IsNullOrWhiteSpace(this.ColumnName)) member.ColumnName = this.ColumnName; if (!string.IsNullOrWhiteSpace(this.Default)) member.ColumnDefault = this.Default; member.Scale = this.Scale; if (this.Precision > 0) member.Precision = this.Precision; if (this.Size != 0) member.Size = this.Size; member.ExplicitDbType = this._dbType; member.ExplicitDbTypeSpec = this.DbTypeSpec; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var linkEntityType = this.LinkEntity; var listInfo = member.ChildListInfo = new ChildEntityListInfo(member); listInfo.RelationType = EntityRelationType.ManyToMany; listInfo.LinkEntity = context.Model.GetEntityInfo(linkEntityType, true); listInfo.ParentRefMember = listInfo.LinkEntity.FindEntityRefMember(this.ThisEntityRef, member.Entity.EntityType, member, context.Log); if(listInfo.ParentRefMember == null) { context.Log.Error( "Many-to-many setup error: back reference to entity {0} not found in link entity {1}.", member.Entity.EntityType, LinkEntity); return; } listInfo.ParentRefMember.ReferenceInfo.TargetListMember = member; var targetEntType = member.DataType.GetGenericArguments()[0]; listInfo.OtherEntityRefMember = listInfo.LinkEntity.FindEntityRefMember(this.OtherEntityRef, targetEntType, member, context.Log); if (listInfo.OtherEntityRefMember != null) listInfo.TargetEntity = context.Model.GetEntityInfo(listInfo.OtherEntityRefMember.DataType, true); }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { if (member.Kind != MemberKind.EntityRef) { context.Log.Error("EntityRef attribute may be used only on properties that are references to other entities. Property: {0}.{1}", member.Entity.Name, member.MemberName); return; } var entity = member.Entity; // Create reference info var targetType = member.DataType; //.Property.PropertyType; var targetEntity = context.Model.GetEntityInfo(targetType); Util.Check(targetEntity != null, "Target entity not found: {0}", targetType); //Create foreign key ForeignKeyName = ForeignKeyName ?? "FK_" + entity.Name + "_" + member.MemberName; var fk = new EntityKeyInfo(ForeignKeyName, KeyType.ForeignKey, entity, member); fk.KeyMembers.Add(new EntityKeyMemberInfo(member, false)); member.ReferenceInfo = new EntityReferenceInfo(member, fk, targetEntity.PrimaryKey); member.ReferenceInfo.ForeignKeyColumns = this.KeyColumns; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { base.Apply(context, attribute, member); var da = (DisplayNameAttribute)attribute; member.DisplayName = da.DisplayName; }
private void ConstructOrderBy(AttributeContext context, EntityInfo entity) { bool error = false; entity.DefaultOrderBy = EntityAttributeHelper.ParseMemberNames(entity, OrderByList, ordered: true, errorAction: spec => { context.Log.Error("Invalid member/spec: {0} in {1} attribute on entity {2}", spec, this.GetAttributeName(), entity.Name); error = true; }); if (error) return; //Check that they are real cols foreach(var ordM in entity.DefaultOrderBy) { if (ordM.Member.Kind != MemberKind.Column) context.Log.Error("Invalid property {0} in OrderBy attribute in entity {1} - must be a plain property.", ordM.Member.MemberName, entity.Name); } }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var listInfo = member.ChildListInfo = new ChildEntityListInfo(member); listInfo.RelationType = EntityRelationType.ManyToOne; var entType = member.Entity.EntityType; var targetType = member.DataType.GetGenericArguments()[0]; listInfo.TargetEntity = context.Model.GetEntityInfo(targetType, true); if (!string.IsNullOrWhiteSpace(this.ThisEntityRef)) { var fkMember = listInfo.TargetEntity.GetMember(this.ThisEntityRef); if (fkMember == null) { context.Log.Error("EntityList member {0}.{1}: could not find property {2} in target entity. ", entType, member.MemberName, this.ThisEntityRef); return; } this.ThisEntityRef = fkMember.MemberName; listInfo.ParentRefMember = fkMember; } else listInfo.ParentRefMember = listInfo.TargetEntity.FindEntityRefMember(this.ThisEntityRef, entType, member, context.Log); //Check that reference is found if(listInfo.ParentRefMember == null) context.Log.Error("EntityList member {0}.{1}: could not find reference property in target entity. ", entType, member.MemberName); else //Set back reference to list from ref member listInfo.ParentRefMember.ReferenceInfo.TargetListMember = member; listInfo.Filter = this.Filter; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { if (member.Kind != MemberKind.EntityList) { context.Log.Error("PersistOrderIn attribute may be specified only on list members. Entity {0}.", member.Entity.Name); return; } EntityInfo orderedEntity = null; //determine the entity that is ordered switch (member.ChildListInfo.RelationType) { case EntityRelationType.ManyToOne: orderedEntity = member.ChildListInfo.TargetEntity; break; case EntityRelationType.ManyToMany: orderedEntity = member.ChildListInfo.LinkEntity; break; } //check that there is a member var orderMember = orderedEntity.GetMember(this.Property); if (orderMember == null) { context.Log.Error("Property '{0}' referenced in PersistOrderIn attribute on entity {1} not found in entity {2}.", this.Property, member.Entity.Name, orderedEntity.Name); return; } //current limitation - index property must be int32 only if (orderMember.DataType != typeof(Int32)) { context.Log.Error("Invalid data type ({0}) for property '{1}' referenced in PersistOrderIn attribute on entity {2}: must be Int32.", orderMember.DataType.Name, this.Property, member.Entity.Name); return; } // Validation passed, assign order member member.ChildListInfo.PersistentOrderMember = orderMember; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { member.Kind = MemberKind.Transient; member.GetValueRef = MemberValueGettersSetters.GetTransientValue; member.SetValueRef = MemberValueGettersSetters.SetTransientValue; }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { entity.OldNames = StringHelper.SplitNames(this.OldNames); }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { var srv = context.Model.App.GetService<IDataHistoryService>(); if(srv != null) srv.RegisterToKeepHistoryData(entity.EntityType); }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { member.Flags |= EntityMemberFlags.IsOwner; if (member.Entity.OwnerMember == null) member.Entity.OwnerMember = member; else context.Log.Error("More than one Owner attribute is specified on entity {0}.", member.Entity.FullName); }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var dataType = member.DataType; member.Flags |= EntityMemberFlags.Utc; if (member.DataType != typeof(DateTime) && member.DataType != typeof(DateTime?)) { context.Log.Error("Utc attribute may be specified only on DataTime properties. Entity.Member: {0}.{1}", member.Entity.Name, member.MemberName); return; } //Inject interceptor _defaultGetter = member.GetValueRef; _defaultSetter = member.SetValueRef; member.GetValueRef = this.GetValueInterceptor; member.SetValueRef = this.SetValueInterceptor; }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { _method = MethodClass.GetMethod(MethodName); if (_method == null) context.Log.Error("Method {0} specified as Validation method for entity {1} not found in type {2}", MethodName, entity.EntityType, MethodClass); entity.Events.ValidatingChanges += Events_Validating; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { member.Flags |= EntityMemberFlags.UnlimitedSize; member.Size = -1; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { member.Flags |= EntityMemberFlags.Secret | EntityMemberFlags.NoDbUpdate; //updates are possible only thru custom update method member.GetValueRef = this.GetSecretValue; }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { if (string.IsNullOrWhiteSpace(this.GroupName)) { context.Log.Error("Group name may not be empty. Entity: {0}.", entity.Name); return; } var names = StringHelper.SplitNames(this.MemberNames); foreach (var name in names) { var member = entity.GetMember(name); if (member == null) { context.Log.Error("PropertyGroup '{0}', entity {1}: member {2} not found.", this.GroupName, entity.Name, name); continue; } var grp = entity.GetPropertyGroup(this.GroupName, create: true); if (!grp.Members.Contains(member)) grp.Members.Add(member); }//foreach }
public virtual void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { }
public virtual void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { }
public virtual void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { // It is initially assigned EntityRef if(!context.Model.IsEntity(member.DataType)) { context.Log.Error("FromBackRef attribute may be used only on properties that are references to other entities. Property: {0}.{1}", member.Entity.Name, member.MemberName); return; } _member = member; _member.Kind = MemberKind.Transient; _member.Flags |= EntityMemberFlags.FromOneToOneRef; _targetEntity = context.Model.GetEntityInfo(member.DataType); Util.Check(_targetEntity != null, "Target entity not found: {0}", member.DataType); //check that PK of target entity points back to 'this' entity var targetPkMembers = _targetEntity.PrimaryKey.KeyMembers; Util.Check(targetPkMembers.Count == 1 && targetPkMembers[0].Member.DataType == _member.Entity.EntityType, "BackRef property {0}.{1}: target entity must have Primary key pointing back to entity {0}.", _member.Entity.Name, _member.MemberName); member.GetValueRef = GetValue; member.SetValueRef = SetValue; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { member.Flags |= EntityMemberFlags.Nullable; if (member.DataType.IsValueType) { member.Flags |= EntityMemberFlags.ReplaceDefaultWithNull; member.GetValueRef = MemberValueGettersSetters.GetValueTypeReplaceNullWithDefault; member.SetValueRef = MemberValueGettersSetters.SetValueTypeReplaceDefaultWithNull; } }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var entity = member.Entity; if (!CreatePrimaryKey(context, entity)) return; entity.PrimaryKey.KeyMembers.Add(new EntityKeyMemberInfo(member, false)); member.Flags |= EntityMemberFlags.PrimaryKey; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { member.OldNames = StringHelper.SplitNames(this.OldNames); }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { // Check size code and lookup in tables if (!string.IsNullOrEmpty(this.SizeCode)) { var sizeTable = context.Model.App.SizeTable; //If there is size code, look it up in SizeTable; first check module-specific value, then global value for the code int size; var fullCode = Sizes.GetFullSizeCode(member.Entity.EntityType.Namespace, this.SizeCode); if (sizeTable.TryGetValue(fullCode, out size)) { //check full code with module's namespace prefix member.Size = size; return; } if (sizeTable.TryGetValue(this.SizeCode, out size)) { //check global value, non-module-specific member.Size = size; return; } } //If size is specified explicitly, use it if(this.Size > 0) { member.Size = Size; if((this.Options & SizeOptions.AutoTrim) != 0) member.Flags |= EntityMemberFlags.AutoTrim; return; } //If no Size code and no value, it is an error, lookup in module settings context.Log.Error("Property {0}.{1}: invalid Size attribute, must specify size code or value", member.Entity.Name, member.MemberName); }
public virtual void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { entity.PagingMode = PagingMode.DataStore; }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { if (string.IsNullOrWhiteSpace(this.MemberNames)) { context.Log.Error("Entity {0}: primary key must specify property name(s) when used on Entity interface.", entity.FullName); return; } if (!CreatePrimaryKey(context, entity)) return; var error = false; var pkMembers = EntityAttributeHelper.ParseMemberNames(entity, this.MemberNames, errorAction: mn => { context.Log.Error("Entity {0}: property {1} listed in PrimaryKey attribute not found.", entity.FullName, mn); error = true; }); if(error) return; foreach(var km in pkMembers) { km.Member.Flags |= EntityMemberFlags.PrimaryKey; entity.PrimaryKey.KeyMembers.Add(km); } }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { var descAttr = (DescriptionAttribute)attribute; entity.Description = descAttr.Description; }
private bool CreatePrimaryKey(AttributeContext context, EntityInfo entity) { if (entity.PrimaryKey != null) { context.Log.Error("More than one primary key specified on entity {0}", entity.FullName); return false; } entity.PrimaryKey = new EntityKeyInfo("PK_" + entity.Name, KeyType.PrimaryKey, entity); if(IsClustered) entity.PrimaryKey.KeyType |= KeyType.Clustered; return true; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var descAttr = (DescriptionAttribute)attribute; member.Description = descAttr.Description; }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { if (!string.IsNullOrWhiteSpace(this.Name)) entity.Name = this.Name; entity.TableName = this.TableName; }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { var descAttr = (DescriptionAttribute)attribute; entity.Description = descAttr.Description; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var descAttr = (DescriptionAttribute)attribute; member.Description = descAttr.Description; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var entity = member.Entity; if (member.Kind == MemberKind.EntityList) { //This is a special case - OrderBy attribute specifies the order of entities in list property. member.ChildListInfo.OrderBy = EntityAttributeHelper.ParseMemberNames(member.ChildListInfo.TargetEntity, this.OrderByList, ordered: true, errorAction: spec => { context.Log.Error("Invalid member/spec: {0} in {1} attribute, property {2}.{3}", spec, this.GetAttributeName(), entity.Name, member.MemberName); }); } else context.Log.Error("OrderBy attribute may be used only on entities or list properties. Entity: {0}, property: {1}", entity.Name, member.MemberName); }