Beispiel #1
0
 public CreateEnumTable(SqlSyntax syntax, Type enumType) : base(syntax, ObjectType.Table, ActionType.Create, $"Enum table {EnumTableName(enumType)}")
 {
     _enumType  = (!enumType.IsNullableEnum()) ? enumType : Nullable.GetUnderlyingType(enumType);
     _attribute =
         enumType.GetAttribute <EnumTableAttribute>() ??
         Nullable.GetUnderlyingType(enumType).GetAttribute <EnumTableAttribute>() ??
         throw new Exception($"Enum type {enumType.Name} is missing an [EnumTable] attribute");
 }
Beispiel #2
0
        public override string CreateEnumTableStatement(Type enumType)
        {
            EnumTableAttribute attr =
                enumType.GetAttribute <EnumTableAttribute>() ??
                Nullable.GetUnderlyingType(enumType).GetAttribute <EnumTableAttribute>() ??
                throw new Exception($"Enum type {enumType.Name} is missing an [EnumTable] attribute");

            return($"CREATE TABLE {ApplyDelimiter(attr.FullTableName())} (\r\n\t[Name] nvarchar(50) NOT NULL,\r\n\t[Value] int NOT NULL PRIMARY KEY\r\n)");
        }
Beispiel #3
0
        public static bool IsEnumForeignKey(this PropertyInfo propertyInfo, out EnumTableAttribute enumTableAttribute)
        {
            EnumTableAttribute enumTableAttribute1 = null;
            EnumTableAttribute enumTableAttribute2 = null;

            try
            {
                bool result =
                    (propertyInfo.PropertyType.IsEnum || propertyInfo.PropertyType.IsNullableEnum()) &&
                    (propertyInfo.PropertyType.HasAttribute(out enumTableAttribute1) || Nullable.GetUnderlyingType(propertyInfo.PropertyType).HasAttribute(out enumTableAttribute2));

                enumTableAttribute = enumTableAttribute1 ?? enumTableAttribute2;

                return(result);
            }
            catch
            {
                enumTableAttribute = null;
                return(false);
            }
        }