private EntityInfo(IFieldPropertyFactory fieldPropertyFactory, EntityInfoCollection entities, Type entityType) { Fields = new DistinctCollection <Field>(); ForeignKeys = new DistinctCollection <ForeignKey>(); References = new DistinctCollection <Reference>(); Indexes = new DistinctCollection <Index>(); Entities = entities; EntityType = entityType; _attributes = entityType.GetCustomAttributes(true); FieldPropertyFactory = fieldPropertyFactory; }
public static IEntityInfo Create(IFieldPropertyFactory fieldPropertyFactory, EntityInfoCollection entities, Type entityType) { if (entities == null) { throw new ArgumentNullException("entities"); } // already added var entityName = entities.GetNameForType(entityType); if (entityName != null) { return(entities[entityName]); } //TODO: validate NameInStore var result = new EntityInfo(fieldPropertyFactory, entities, entityType); if (result.EntityAttribute == null) { throw new ArgumentException($"Type '{entityType.Name}' does not have an EntityAttribute"); } entities.Add(result); // see if we have any entity // get all field definitions foreach (var prop in GetProperties(entityType)) { result.AnalyseAttribute(prop); } if (result.Fields.Count == 0) { throw new EntityDefinitionException( $"Entity '{result.GetNameInStore()}' Contains no Field definitions."); } //Update Reference atribute with new known type foreach (var entityInfo in entities) { var entity = entityInfo as EntityInfo; entity?.UpdateRefenceAttribute(); } return(result); }
protected DataStore() { Entities = new EntityInfoCollection(); }