Ejemplo n.º 1
0
        private IInsqlEntityMap CreateAnnotationEntityMap(Type entityType)
        {
            TableAttribute tableAttribute = (TableAttribute)entityType.GetCustomAttribute(typeof(TableAttribute), true);

            IInsqlEntityMap resultMap = new InsqlEntityMap(entityType, tableAttribute.Name, tableAttribute.Schema);

            var columnMaps = entityType.GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(propInfo =>
            {
                ColumnAttribute columnAttribute       = (ColumnAttribute)propInfo.GetCustomAttribute(typeof(ColumnAttribute), true);
                KeyAttribute keyAttribute             = (KeyAttribute)propInfo.GetCustomAttribute(typeof(KeyAttribute), true);
                NotMappedAttribute notMappedAttribute = (NotMappedAttribute)propInfo.GetCustomAttribute(typeof(NotMappedAttribute), true);
                EditableAttribute editableAttribute   = (EditableAttribute)propInfo.GetCustomAttribute(typeof(EditableAttribute), true);
                DatabaseGeneratedAttribute databaseGeneratedAttribute = (DatabaseGeneratedAttribute)propInfo.GetCustomAttribute(typeof(DatabaseGeneratedAttribute), true);

                InsqlPropertyMap propertyMap = new InsqlPropertyMap(propInfo, columnAttribute?.Name);

                if (keyAttribute != null)
                {
                    propertyMap.IsKey = true;
                }
                if (notMappedAttribute != null)
                {
                    propertyMap.IsIgnored = true;
                }
                if (databaseGeneratedAttribute != null)
                {
                    if (databaseGeneratedAttribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity)
                    {
                        propertyMap.IsIdentity = true;
                    }
                }
                if (editableAttribute != null && !editableAttribute.AllowEdit)
                {
                    propertyMap.IsReadonly = true;
                }

                return(propertyMap);
            });

            foreach (var columnMap in columnMaps)
            {
                resultMap.Properties.Add(columnMap);
            }

            InsqlEntityValidator.Instance.Validate(resultMap);

            return(resultMap);
        }
Ejemplo n.º 2
0
 public InsqlEntityBuilder(Type entityType)
 {
     this.entityMap = new InsqlEntityMap(entityType);
 }