Example #1
0
        private void CacheTableInfo(Type entityType)
        {
            var tableAttribute = entityType.GetCustomAttribute <TableAttribute>();

            if (tableAttribute == null)
            {
                throw new InvalidOperationException("Table attribute must be specified to the Entity");
            }

            var tableInfo = new TableInfo(tableAttribute.Name);

            foreach (var propertyInfo in entityType.GetProperties())
            {
                var columnAttribute = propertyInfo.GetCustomAttribute <ColumnAttribute>();
                if (columnAttribute != null)
                {
                    tableInfo.AddColumnMapping(columnAttribute.Name, propertyInfo.Name);
                    if (columnAttribute.IsPrimary)
                    {
                        tableInfo.SetKey(columnAttribute.Name);
                        tableInfo.SetAutoIncrement(columnAttribute.AutoIncrement);
                    }
                }
            }

            _tableInfos.Add(entityType, tableInfo);
        }