Esempio n. 1
0
        private string GenerateSqlMapping()
        {
            var tSourceType = typeof(T);
            var columnList  = new List <string>();

            Properties = tSourceType.GetProperties();

            MappedColumns = Properties.Where(property => property.CustomAttributes.Any(customAttribute =>
                                                                                       customAttribute.AttributeType == typeof(ColumnAttribute))).ToDictionary(a => a.Name,
                                                                                                                                                               a => a.CustomAttributes.FirstOrDefault(b => b.AttributeType == typeof(ColumnAttribute)));

            KeyProperties = Properties.Where(property => property.CustomAttributes.Any(customAttribute =>
                                                                                       customAttribute.AttributeType == typeof(KeyAttribute))).ToArray();

            IdentityProperty = Properties.SingleOrDefault(property => property.CustomAttributes.Any(customAttribute =>
                                                                                                    customAttribute.AttributeType == typeof(IdentityAttribute))) ?? KeyProperties.FirstOrDefault();

            foreach (var property in GetProperties(Properties))
            {
                var propertyName = property;

                if (MappedColumns.ContainsKey(propertyName))
                {
                    var constructorArguments = MappedColumns[propertyName].ConstructorArguments;

                    if (constructorArguments.Any())
                    {
                        propertyName = constructorArguments.SingleOrDefault().Value.ToString();
                    }
                }

                columnList.Add(propertyName);
            }

            Columns = columnList;

            return(GetSchemaTable(tSourceType));
        }
Esempio n. 2
0
 bool IMappedType.ColumnHasBeenMapped(string columnName)
 {
     return(MappedColumns.ContainsKey(columnName));
 }