예제 #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());
     }
 }
예제 #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
                });
            }
        }
예제 #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);
            }
        }
예제 #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 });
            //}
        }
예제 #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);
            //}
        }
예제 #6
0
 private static void AddMaxLengthConstraintIfNecessary(IColumnMapping property, ColumnStatement columnStatement)
 {
     if (property.MaxLength.HasValue)
     {
         columnStatement.ColumnConstraints.Add(new MaxLengthConstraint(property.MaxLength.Value));
     }
 }
예제 #7
0
        private static void ConvertIntegerType(ColumnStatement columnStatement)
        {
            const string integerType = "INTEGER";

            columnStatement.TypeName = columnStatement.TypeName.ToUpperInvariant() == "INT" ? integerType : columnStatement.TypeName;
        }
예제 #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);
        }
예제 #9
0
 private static void AddDefaultValueConstraintIfNecessary(IColumnMapping property, ColumnStatement columnStatement)
 {
     if (!string.IsNullOrEmpty(property.DefaultValue))
     {
         columnStatement.ColumnConstraints.Add(new DefaultValueConstraint {
             DefaultValue = property.DefaultValue
         });
     }
 }