Exemple #1
0
        private void SetAnnotatedColumn(ColumnModel column, string tableName)
        {
            AnnotationValues values;

            if (column.Annotations.TryGetValue(AnnotationName, out values))
            {
                string newValue = (values.NewValue as string);
                if (newValue == null)
                {
                    using (var writer = Writer())
                    {
                        // Drop Constraint
                        string sql = GetSqlDropUniqueIndexQuery(tableName, column.Name);
                        writer.WriteLine(sql);
                        Statement(writer);
                    }
                }
                else
                {
                    UniqueIndex newValueIndex = UniqueIndex.DeserializeFromString(newValue);
                    using (var writer = Writer())
                    {
                        // Add Constraint
                        string sql = GetSqlAddUniqueIndexQuery(tableName, column.Name, newValueIndex.AllowNull, newValueIndex.ColumnNames);
                        writer.WriteLine(sql);
                        Statement(writer);
                    }
                }
            }
        }
Exemple #2
0
        public static UniqueIndex DeserializeFromString(string value)
        {
            UniqueIndex ret = null; if (string.IsNullOrEmpty(value) == false)

            {
                string[] tmp = value.Split(','); ret = new UniqueIndex()
                {
                    AllowNull = tmp.Select(_ => bool.Parse(_)).ElementAtOrDefault(0), ColumnNames = tmp.Skip(1).ToArray(),
                };
            }
            return(ret);
        }
Exemple #3
0
 //
 public static string SerializeToString(UniqueIndex value)
 {
     return((value != null) ? $@"{value.AllowNull},{string.Join(",", value.ColumnNames)}" : null);
 }