public void UniqueNamerTest() { var namer = new UniqueNamer(); Assert.IsNotNull(namer); string result; result = namer.UniqueName("Tester", "Users"); Assert.AreEqual("Users", result); result = namer.UniqueName("Tester", "Users"); Assert.AreEqual("Users1", result); result = namer.UniqueName("Tester", "Users"); Assert.AreEqual("Users2", result); }
private void CreateProperties(Entity entity, IEnumerable <DataObjectBase> columnSchemaCollection) { foreach (DataObjectBase dataObjectBase in columnSchemaCollection) { // skip unsupported type if (dataObjectBase.NativeType.Equals("hierarchyid", StringComparison.OrdinalIgnoreCase) || dataObjectBase.NativeType.Equals("sql_variant", StringComparison.OrdinalIgnoreCase)) { Debug.WriteLine("Skipping column '{0}' because it has an unsupported db type '{1}'.", dataObjectBase.Name, dataObjectBase.NativeType); continue; } Property property = entity.Properties.ByColumn(dataObjectBase.Name); if (property == null) { property = new Property { ColumnName = dataObjectBase.Name }; entity.Properties.Add(property); } string propertyName = ToPropertyName(entity.ClassName, dataObjectBase.Name); propertyName = _namer.UniqueName(entity.ClassName, propertyName); property.PropertyName = propertyName; property.DataType = dataObjectBase.DataType; property.SystemType = dataObjectBase.SystemType; property.NativeType = dataObjectBase.NativeType; property.IsNullable = dataObjectBase.AllowDBNull; property.IsIdentity = IsIdentity(dataObjectBase); property.IsRowVersion = IsRowVersion(dataObjectBase); property.IsAutoGenerated = IsDbGenerated(dataObjectBase); property.Default = GetDefaultValue(dataObjectBase); if (property.SystemType == typeof(string) || property.SystemType == typeof(byte[])) { property.MaxLength = dataObjectBase.Size; } if (property.SystemType == typeof(float) || property.SystemType == typeof(double) || property.SystemType == typeof(decimal)) { property.Precision = dataObjectBase.Precision; property.Scale = dataObjectBase.Scale; } var columnSchema = dataObjectBase as ColumnSchema; if (columnSchema != null) { property.IsPrimaryKey = columnSchema.IsPrimaryKeyMember; property.IsForeignKey = columnSchema.IsForeignKeyMember; if (columnSchema.IsUnique) { property.IsUnique = true; } } property.IsProcessed = true; } entity.Properties.IsProcessed = true; }
/// <summary> /// 创建实体的属性 /// </summary> private void CreateProperties(Entity entity, TableSchema tableSchema) { foreach (ColumnSchema columnSchema in tableSchema.Columns) { // skip unsupported type if (columnSchema.NativeType.Equals("hierarchyid", StringComparison.OrdinalIgnoreCase) || columnSchema.NativeType.Equals("sql_variant", StringComparison.OrdinalIgnoreCase)) { Debug.WriteLine(string.Format("Skipping column '{0}' because it has an unsupported db type '{1}'.", columnSchema.Name, columnSchema.NativeType)); continue; } Property property = entity.Properties.ByColumn(columnSchema.Name); if (property == null) { property = new Property { ColumnName = columnSchema.Name }; entity.Properties.Add(property); } string propertyName = ToPropertyName(entity.ClassName, columnSchema.Name); propertyName = _namer.UniqueName(entity.ClassName, propertyName); property.PropertyName = propertyName; property.DataType = columnSchema.DataType; property.SystemType = columnSchema.SystemType; property.NativeType = columnSchema.NativeType; property.Description = columnSchema.Description; property.IsPrimaryKey = columnSchema.IsPrimaryKeyMember; property.IsForeignKey = columnSchema.IsForeignKeyMember; property.IsNullable = columnSchema.AllowDBNull; property.IsIdentity = IsIdentity(columnSchema); property.IsRowVersion = IsRowVersion(columnSchema); property.IsAutoGenerated = IsDbGenerated(columnSchema); if (columnSchema.IsUnique) { property.IsUnique = columnSchema.IsUnique; } if (property.SystemType == typeof(string) || property.SystemType == typeof(byte[])) { property.MaxLength = columnSchema.Size; } if (property.SystemType == typeof(float) || property.SystemType == typeof(double) || property.SystemType == typeof(decimal)) { property.Precision = columnSchema.Precision; property.Scale = columnSchema.Scale; } property.IsProcessed = true; } entity.Properties.IsProcessed = true; }