/// <summary> /// Called on entity's insertion. /// </summary> /// <param name="entity">The entity.</param> /// <param name="index">The index.</param> protected virtual void OnEntityInsertion(MetaEntity entity, int index) { entity.Parent = _parentEntity; if (_parentEntity.Model != null) { entity.OnModelAssignment(); } }
/// <summary> /// Inserts an element into the <see cref="T:System.Collections.ObjectModel.Collection`1"/> at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param> /// <param name="item">The object to insert. The value can be null for reference types.</param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="index"/> is less than zero. /// -or- /// <paramref name="index"/> is greater than <see cref="P:System.Collections.ObjectModel.Collection`1.Count"/>. /// </exception> protected override void InsertItem(int index, MetaEntity item) { if (item == this._parentEntity) { throw new ArgumentException("Can't add an entity to itself"); } base.InsertItem(index, item); OnEntityInsertion(item, index); }
/// <summary> /// Sorts the content of one entity alphabetically. /// This function is called by <see cref="SortEntities" /> method /// </summary> /// <param name="entity">The entity.</param> protected virtual void SortEntityContent(MetaEntity entity) { entity.SubEntities.SortByName(); foreach (var ent in entity.SubEntities) { SortEntityContent(ent); } entity.Attributes.SortByCaption(); }
/// <summary> /// Adds a sub-entity to the current entity. /// </summary> /// <param name="entity">The parent entity.</param> /// <param name="entityName">The name of the new entity.</param> /// <returns>Entity.</returns> public MetaEntity AddEntity(MetaEntity entity, string entityName) { if (entity == null) { entity = EntityRoot; } var ent = CreateEntity(entity); ent.Name = entityName; entity.SubEntities.Add(ent); return(ent); }
public MetaEntityAttrDescriptor(MetaEntity parent, string expr) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } Parent = parent; Expression = expr; Caption = expr?.GetSecondPart('.'); Kind = EntityAttrKind.Data; DataType = DataType.Unknown; Size = 100; }
/// <summary> /// Adds a sub-entity to the current entity. /// </summary> /// <param name="entity">The parent entity.</param> /// <param name="entityName">The name of the new entity.</param> /// <returns>Entity.</returns> public MetaEntity AddEntity(MetaEntity entity, string entityName) { if (entity == null) { entity = EntityRoot; } var ent = CreateEntity(entity); ent.Id = DataUtils.ComposeKey(entity?.Id, entityName); ent.Name = entityName; entity.SubEntities.Add(ent); return(ent); }
/// <summary> /// Checks the Model property and raises an exception if it's null. /// </summary> /// <exception cref="MetaDataException"> /// Entity is not specified for attribute: + {attribute ID} /// or /// Model is not specified for entity: + {entity ID} /// </exception> protected void CheckModel() { if (Entity == null) { throw new MetaDataException("Entity is not specified for attribute: " + this.Id); } if (Model == null) { MetaEntity ent = Entity; while (ent.Parent != null) { ent = ent.Parent; } throw new MetaDataException(string.Format("Model is not specified for entity: {0}, root: {1}", ent.Name, ent.IsRoot.ToString())); } }
/// <summary> /// Adds a new attribute to the model. /// </summary> /// <param name="entity">The parent entity.</param> /// <param name="expression">The attribute's expression.</param> /// <param name="caption">The attribute's caption.</param> /// <param name="dataType">The type of the data.</param> /// <param name="isVirtual">The type of the data.</param> /// <param name="size">The size (if necessary).</param> /// <returns>EntityAttr.</returns> public virtual MetaEntityAttr AddEntityAttr(MetaEntity entity, string expression, string caption = null, DataType dataType = DataType.String, bool isVirtual = false, int size = 100) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } var attr = CreateEntityAttr(entity, isVirtual); attr.Expr = expression; if (string.IsNullOrEmpty(caption)) { caption = expression.GetSecondPart('.'); } attr.Caption = caption; attr.DataType = dataType; attr.Size = size; entity.Attributes.Add(attr); return(attr); }
protected internal MetaEntityAttr(MetaEntity parentEntity, bool isVirtual = false) : this(parentEntity, isVirtual ? EntityAttrKind.Virtual : EntityAttrKind.Data) { }
protected virtual MetaEntityAttr CreateEntityAttrCore(MetaEntity parent, EntityAttrKind kind) { return(new MetaEntityAttr(parent, kind)); }
protected virtual MetaEntity CreateEntityCore(MetaEntity parent) { return(new MetaEntity(parent)); }
public MetaEntityAttrDescriptor(MetaEntity parent, EntityAttrKind kind, string expr = "") : this(parent, expr) { Kind = kind; }
/// <summary> /// Creates the entity. /// </summary> /// <returns></returns> public MetaEntity CreateEntity(MetaEntity parentEntity = null) { return(CreateEntityCore(parentEntity ?? EntityRoot)); }
public MetaEntityAttrDescriptor(MetaEntity parent) : this(parent, "") { }
/// <summary> /// Initializes a new instance of the <see cref="T:EasyData.MetaEntityAttr" /> class. /// </summary> /// <param name="parentEntity"></param> /// <param name="kind"></param> public MetaEntityAttr(MetaEntity parentEntity, EntityAttrKind kind) { Entity = parentEntity; Kind = kind; }
/// <summary> /// Creates the entity attribute. Used for creating entity attributes while building the model /// </summary> /// <param name="parentEntity">The parent entity.</param> /// <param name="isVirtual">if set to <c>true</c> the new attribute will be a virtual one.</param> /// <returns>EntityAttr.</returns> public virtual MetaEntityAttr CreateEntityAttr(MetaEntity parentEntity = null, bool isVirtual = false) { return(new MetaEntityAttr(parentEntity, isVirtual)); }
/// <summary> /// Adds a new attribute to the model. /// </summary> /// <param name="entity">The parent entity.</param> /// <param name="expression">The attribute's expression.</param> /// <param name="caption">The attribute's caption.</param> /// <param name="dataType">The type of the data.</param> /// <param name="size">The size (if necessary).</param> /// <returns>EntityAttr.</returns> public MetaEntityAttr AddEntityAttr(MetaEntity entity, string expression, string caption = null, DataType dataType = DataType.String, int size = 100) { return(AddEntityAttr(entity, expression, caption, dataType, false, size)); }
/// <summary> /// Creates the entity. /// </summary> /// <returns></returns> public virtual MetaEntity CreateEntity(MetaEntity parentEntity = null) { return(new MetaEntity(parentEntity ?? EntityRoot)); }
/// <summary> /// Creates the entity attribute. Used for creating entity attributes while building the model /// </summary> /// <param name="parentEntity">The parent entity.</param> /// <returns></returns> public virtual MetaEntityAttr CreateLookupEntityAttr(MetaEntity parentEntity) { return(new MetaEntityAttr(parentEntity, EntityAttrKind.Lookup)); }
/// <summary> /// Initializes a new instance of the <see cref="T:EntityStore"/> class. /// </summary> /// <param name="parentEntity">The parent entity.</param> public MetaEntityStore(MetaEntity parentEntity) { _parentEntity = parentEntity; }
protected internal MetaEntityAttr(MetaEntity parentEntity, EntityAttrKind kind) { Entity = parentEntity; Kind = kind; }
/// <summary> /// Initializes a new instance of the <see cref="T:EntityAttrStore"/> class. /// </summary> /// <param name="entity">The entity.</param> public MetaEntityAttrStore(MetaEntity entity) : base() { _entity = entity; }
/// <summary> /// Initializes a new instance of the <see cref="T:EasyData.MetaEntityAttr" /> class. /// </summary> /// <param name="parentEntity">The parent entity.</param> /// <param name="isVirtual">if set to <c>true</c> the created attribute will be virtual (calculated).</param> public MetaEntityAttr(MetaEntity parentEntity, bool isVirtual = false) : this(parentEntity, isVirtual ? EntityAttrKind.Virtual : EntityAttrKind.Data) { }