Beispiel #1
0
 public Column(EntityTable table, string name)
 {
     Table        = table;
     Restrictions = new List <Restriction>();
     Parameters   = new List <Parameter>();
     Name         = name;
     Alias        = $"{table.Type.Name}.{Name}";
     PropertyName = string.Empty;
     PropertyType = typeof(object);
 }
Beispiel #2
0
        public EntityColumn(ColumnAttribute columnAttribute, EntityTable table)
            : base(table, columnAttribute.ColumnName)
        {
            ColumnAttribute = columnAttribute;
            ColumnType      = ColumnTypes.EntityColumn;
            DataColumn      = new DataColumn(Name);

            GetPropertyInfo();

            Logger.Trace($"Loaded database mapping for Property '{PropertyName}' of Entity '{Table.Type.Name}' (Column '{Name}')");
        }
Beispiel #3
0
        public FormulaColumn(FormulaAttribute formulaAttribute, EntityTable table)
            : base(table, formulaAttribute.Alias)
        {
            FormulaAttribute = formulaAttribute;
            Alias            = Name;
            Formula          = formulaAttribute.Query;
            ColumnType       = ColumnTypes.FormulaColumn;

            GetPropertyInfo();

            Logger.Trace($"Loaded database mapping for Property '{PropertyName}' of Entity '{Table.Type.Name}' (Column '{Name}')");
        }
Beispiel #4
0
        internal void UpdateForeignKeys(dynamic primaryKey, int entityIndex)
        {
            Logger.Trace($"Updating foreign keys of child entities of '{Type.Name}' entity");

            IEntity entity = Entities[entityIndex];

            foreach (IEntity childEntity in entity.GetChildren())
            {
                Type        type  = childEntity.GetType();
                EntityTable table = Mapping.TypeTableMapping[type];
                table.SetForeignKeyValue(childEntity, primaryKey);
            }
        }
Beispiel #5
0
        protected bool TryGetTable(Type type, out EntityTable?table)
        {
            AttributeWrapper attributes = new AttributeWrapper(type);

            if (attributes.IsValid())
            {
                table = new EntityTable(type, attributes);
                return(true);
            }

            table = null;
            return(false);
        }
Beispiel #6
0
        protected void MapTablesByProperty(PropertyInfo property, EntityTable parentTable)
        {
            Type propertyType = property.PropertyType;

            // If the property is a generic list, then it fits the profile of a child object
            if (ReflectionUtil.IsGenericList(propertyType))
            {
                Type genericArgumentType = propertyType.GetGenericArguments()[0];

                MapType(genericArgumentType);

                EntityTable mappedTable = TypeTableMapping[genericArgumentType];

                mappedTable.ParentTable = parentTable;
                parentTable.ChildTables.Add(mappedTable);
            }
        }
Beispiel #7
0
        protected void MapType(Type type)
        {
            if (!TypeTableMapping.ContainsKey(type))
            {
                EntityTable table = GetTableByType(type);

                table.Mapping = this;

                Tables.Add(table);
                TypeTableMapping.Add(type, table);

                foreach (PropertyInfo prop in type.GetProperties())
                {
                    MapTablesByProperty(prop, table);
                }
            }
        }
Beispiel #8
0
 public EntityColumn GetForeignKeyColumnFor(EntityTable foreignTable)
 {
     return(foreignKeyColumnsDict[foreignTable.Name] ?? throw new TableMappingException(Type, Name));
 }