public void FillContext(WorksheetContext ctx) { ctx.Context.Entites.ForEach((e) => { Attribute attribute = e.Attributes.FirstOrDefault(a => a.IsTypeOf <Table>()); if (attribute.IsNotNull()) { Table table = attribute.CastToType <Table>(); if (_dataSet.Tables.Contains(table.TableName)) { IEntityCollection collection = e.Entities as IEntityCollection; if (collection.IsNotNull()) { foreach (DataRow row in _dataSet.Tables[table.TableName].Rows) { Entity entity = collection.CreateInstance(e.EntityType, true, new object[] { row }) as Entity; if (entity.IsNotNull()) { collection.Add(entity); } } } } } }); ctx.AcceptChanges(); }
internal void SetValue(string name, object value, Type propertyType) { if (EntityCtx.DynamicProperties.IsNotNull()) { IEnumerable <Entity> entities = this[EntityCtx.DynamicProperties.Property.Name] as IEnumerable <Entity>; if (entities.IsNotNull()) { Entity entity = entities.FirstOrDefault(e => e[EntityCtx.DynamicProperties.CodeProperty].IsNotNull() && e[EntityCtx.DynamicProperties.CodeProperty].Equals(name)); if (entity.IsNotNull()) { if (EntityCtx.DynamicProperties.ValuesProperties.ContainsKey(propertyType)) { entity[EntityCtx.DynamicProperties.ValuesProperties[propertyType]] = value; } } else { IEntityCollection collection = entities as IEntityCollection; if (collection.IsNotNull()) { entity = collection.CreateInstance(EntityCtx.DynamicProperties.Property.ReletedEntity.RelatedEntity.EntityType, true, null) as Entity; if (entity.IsNotNull()) { if (EntityCtx.DynamicProperties.ValuesProperties.ContainsKey(propertyType)) { entity[EntityCtx.DynamicProperties.ValuesProperties[propertyType]] = value; } entity[EntityCtx.DynamicProperties.CodeProperty] = name; collection.Add(entity); } } } } } }