Exemple #1
0
 private static void AddNullConstraintIfNecessary(IColumnMapping property, ColumnStatement columnStatement)
 {
     // TJT: Review this
     if (property.IsRequired)
     {
         // Only mark it as NotNull if it should not be generated.
         columnStatement.ColumnConstraints.Add(new NotNullConstraint());
     }
 }
Exemple #2
0
        private static void AddUniqueConstraintIfNecessary(IColumnMapping property, ColumnStatement columnStatement)
        {
            var value = property.IsUnique;

            if (property.IsUnique)
            {
                var conflictAction = ConflictAction.None;
                columnStatement.ColumnConstraints.Add(new UniqueConstraint {
                    ConflictAction = conflictAction
                });
            }
        }
Exemple #3
0
        private IEnumerable <ColumnStatement> CreateColumnStatements()
        {
            foreach (var property in properties)
            {
                var columnStatement = new ColumnStatement
                {
                    ColumnName = property.ColumnName,
                    TypeName   = property.ColumnDataType,

                    ColumnConstraints = new ColumnConstraintCollection()
                };

                AddMaxLengthConstraintIfNecessary(property, columnStatement);
                AdjustDatatypeForAutogenerationIfNecessary(property, columnStatement);
                AddNullConstraintIfNecessary(property, columnStatement);
                AddUniqueConstraintIfNecessary(property, columnStatement);
                AddCollationConstraintIfNecessary(property, columnStatement);
                AddPrimaryKeyConstraintAndAdjustTypeIfNecessary(property, columnStatement);
                AddDefaultValueConstraintIfNecessary(property, columnStatement);

                yield return(columnStatement);
            }
        }
Exemple #4
0
        private static void AddCollationConstraintIfNecessary(IColumnMapping property, ColumnStatement columnStatement)
        {
            // FIXME:

            //var value = property.GetCustomAnnotation<CollateAttribute>();
            //if (value != null)
            //{
            //    columnStatement.ColumnConstraints.Add(new CollateConstraint { CollationFunction = value.Collation, CustomCollationFunction = value.Function });
            //}
        }
Exemple #5
0
        private static void AdjustDatatypeForAutogenerationIfNecessary(IColumnMapping property, ColumnStatement columnStatement)
        {
            // FIXME:

            //if (property.StoreGeneratedPattern == StoreGeneratedPattern.Identity)
            //{
            //    // Must be INTEGER else SQLite will not generate the Ids
            //    ConvertIntegerType(columnStatement);
            //}
        }
Exemple #6
0
 private static void AddMaxLengthConstraintIfNecessary(IColumnMapping property, ColumnStatement columnStatement)
 {
     if (property.MaxLength.HasValue)
     {
         columnStatement.ColumnConstraints.Add(new MaxLengthConstraint(property.MaxLength.Value));
     }
 }
Exemple #7
0
        private static void ConvertIntegerType(ColumnStatement columnStatement)
        {
            const string integerType = "INTEGER";

            columnStatement.TypeName = columnStatement.TypeName.ToUpperInvariant() == "INT" ? integerType : columnStatement.TypeName;
        }
Exemple #8
0
        private void AddPrimaryKeyConstraintAndAdjustTypeIfNecessary(IColumnMapping property, ColumnStatement columnStatement)
        {
            // Only handle a single primary key this way.

            if (keyMembers.Count() != 1 || !property.Equals(keyMembers.Single()))
            {
                return;
            }

            ConvertIntegerType(columnStatement);
            var primaryKeyConstraint = new PrimaryKeyConstraint();

            // FIXME: primaryKeyConstraint.Autoincrement = property.Autoincrement() != null;

            columnStatement.ColumnConstraints.Add(primaryKeyConstraint);
        }
Exemple #9
0
 private static void AddDefaultValueConstraintIfNecessary(IColumnMapping property, ColumnStatement columnStatement)
 {
     if (!string.IsNullOrEmpty(property.DefaultValue))
     {
         columnStatement.ColumnConstraints.Add(new DefaultValueConstraint {
             DefaultValue = property.DefaultValue
         });
     }
 }