Removing attributes for migrations as a library that does this already exists.

Updating a few DTOs for programmatic creation.
This commit is contained in:
Morten@Thinkpad-X220.ab-nat1.dk
2012-10-17 10:12:30 -02:00
parent 2523781fc1
commit 5bd2059cd7
28 changed files with 112 additions and 286 deletions

View File

@@ -57,7 +57,7 @@
string syntax = string.Empty;
if (attribute.AutoIncrement)
syntax = "IDENTITY(1, 1)";
syntax = " IDENTITY(1, 1)";
return syntax;
}
@@ -70,8 +70,11 @@
if (DatabaseFactory.Current.DatabaseProvider == DatabaseProviders.SqlServerCE)
clustered = string.Empty;
string syntax = string.Format("ALTER TABLE [{0}] ADD CONSTRAINT [{1}] PRIMARY KEY {2} ([{3}])", tableName,
constraintName, clustered, propertyName);
string syntax = string.IsNullOrEmpty(attribute.OnColumns)
? string.Format("ALTER TABLE [{0}] ADD CONSTRAINT [{1}] PRIMARY KEY {2} ([{3}])",
tableName, constraintName, clustered, propertyName)
: string.Format("ALTER TABLE [{0}] ADD CONSTRAINT [{1}] PRIMARY KEY {2} ({3})",
tableName, constraintName, clustered, attribute.OnColumns);
return syntax;
}
@@ -90,7 +93,9 @@
var primaryKeyAttribute = attribute.Type.FirstAttribute<PrimaryKeyAttribute>();
var referencedTableName = tableNameAttribute.Value;
string constraintName = string.Format("FK_{0}_{1}", tableName, referencedTableName);
string constraintName = string.IsNullOrEmpty(attribute.Name)
? string.Format("FK_{0}_{1}", tableName, referencedTableName)
: attribute.Name;
string syntax =
string.Format(
"ALTER TABLE [{0}] ADD CONSTRAINT [{1}] FOREIGN KEY ([{2}]) REFERENCES [{3}] ([{4}])",
@@ -107,7 +112,7 @@
case IndexTypes.Clustered:
indexType = "CLUSTERED";
break;
case IndexTypes.Nonclustered:
case IndexTypes.NonClustered:
indexType = "NONCLUSTERED";
break;
case IndexTypes.PrimaryXml:
@@ -116,8 +121,8 @@
case IndexTypes.Spartial:
indexType = "SPARTIAL";
break;
case IndexTypes.UniqueNonclustered:
indexType = "UNIQUENONCLUSTERED";
case IndexTypes.UniqueNonClustered:
indexType = "UNIQUE NONCLUSTERED";
break;
}
string name = string.IsNullOrEmpty(attribute.Name) ? string.Format("IX_{0}_{1}", tableName, propertyName) : attribute.Name;

View File

@@ -12,6 +12,6 @@ namespace Umbraco.Core.Persistence.DatabaseAnnotations
public string OnDelete { get; set; }
public string OnUpdate { get; set; }
//Default naming: FK_thisTableName_refTableName
public string Name { get; set; }//Used to override Default naming: FK_thisTableName_refTableName
}
}

View File

@@ -3,8 +3,8 @@
public enum IndexTypes
{
Clustered,
Nonclustered,
UniqueNonclustered,
NonClustered,
UniqueNonClustered,
PrimaryXml,
Spartial
}

View File

@@ -14,5 +14,6 @@ namespace Umbraco.Core.Persistence.DatabaseAnnotations
public bool Clustered { get; set; }//Defaults to true
public bool AutoIncrement { get; set; }//Default to true
public string Name { get; set; }//Overrides the default naming of a PrimaryKey constraint: PK_tableName
public string OnColumns { get; set; }
}
}