diff --git a/Rafy/Rafy/DbMigration/DbMigrationContext.cs b/Rafy/Rafy/DbMigration/DbMigrationContext.cs index 2a687264a..54e299a0b 100644 --- a/Rafy/Rafy/DbMigration/DbMigrationContext.cs +++ b/Rafy/Rafy/DbMigration/DbMigrationContext.cs @@ -221,7 +221,7 @@ public void MigrateTo(DestinationDatabase destination) var dbMeta = this.DatabaseMetaReader.Read(); - var differ = new ModelDiffer(); + var differ = new ModelDiffer((_runGenerator as SqlRunGenerator).DbTypeCoverter); differ.IDbIdentifierProvider = (_runGenerator as SqlRunGenerator).IdentifierQuoter; var changeSet = differ.Distinguish(dbMeta, destination); diff --git a/Rafy/Rafy/DbMigration/Model/Differ/ModelDiffer.cs b/Rafy/Rafy/DbMigration/Model/Differ/ModelDiffer.cs index c924d76fa..b98de41a2 100644 --- a/Rafy/Rafy/DbMigration/Model/Differ/ModelDiffer.cs +++ b/Rafy/Rafy/DbMigration/Model/Differ/ModelDiffer.cs @@ -24,6 +24,13 @@ internal class ModelDiffer { internal IDbIdentifierQuoter IDbIdentifierProvider; + private DbTypeConverter dbTypeConverter; + + internal ModelDiffer(DbTypeConverter dbTypeConverter) + { + this.dbTypeConverter = dbTypeConverter; + } + /// /// 计算出两个数据库元数据的所有表差别 /// @@ -137,7 +144,7 @@ private ColumnChanges Distinguish(Column oldColumn, Column newColumn) if (newColumn.IsPrimaryKey != oldColumn.IsPrimaryKey) { columnChanged.IsPrimaryKeyChanged = true; } - if (!DbTypeConverter.IsCompatible(newColumn.DbType, oldColumn.DbType)) { columnChanged.IsDbTypeChanged = true; } + if (!dbTypeConverter.IsCompatible(newColumn.DbType, oldColumn.DbType)) { columnChanged.IsDbTypeChanged = true; } //ForeignRelationChangeType columnChanged.ForeignRelationChangeType = ChangeType.UnChanged; @@ -164,7 +171,7 @@ private bool Equals(Column a, Column b) { if (a.Table.Name.EqualsIgnoreCase(b.Table.Name) && a.Name.EqualsIgnoreCase(b.Name) && - DbTypeConverter.IsCompatible(a.DbType, b.DbType) && + dbTypeConverter.IsCompatible(a.DbType, b.DbType) && //a.DataType == b.DataType && a.IsRequired == b.IsRequired && a.IsForeignKey == b.IsForeignKey && diff --git a/Rafy/Rafy/DbMigration/Providers/DbTypeConverter.cs b/Rafy/Rafy/DbMigration/Providers/DbTypeConverter.cs index cfa6b5084..1a4049a24 100644 --- a/Rafy/Rafy/DbMigration/Providers/DbTypeConverter.cs +++ b/Rafy/Rafy/DbMigration/Providers/DbTypeConverter.cs @@ -54,6 +54,7 @@ public virtual DbType FromClrType(Type clrType) if (clrType == typeof(long)) { return DbType.Int64; } if (clrType == typeof(bool)) { return DbType.Boolean; } if (clrType == typeof(DateTime)) { return DbType.DateTime; } + if (clrType == typeof(DateTimeOffset)) { return DbType.DateTimeOffset; } if (clrType == typeof(Guid)) { return DbType.Guid; } if (clrType == typeof(double)) { return DbType.Double; } if (clrType == typeof(byte)) { return DbType.Byte; } @@ -146,7 +147,7 @@ internal virtual object GetDefaultValue(DbType type) /// /// /// - internal static bool IsCompatible(DbType oldColumnType, DbType newColumnType) + internal virtual bool IsCompatible(DbType oldColumnType, DbType newColumnType) { if (oldColumnType == newColumnType) return true; diff --git a/Rafy/Rafy/DbMigration/Providers/MySql/MySqlDbTypeConverter.cs b/Rafy/Rafy/DbMigration/Providers/MySql/MySqlDbTypeConverter.cs index 31464b966..ed9f1a01c 100644 --- a/Rafy/Rafy/DbMigration/Providers/MySql/MySqlDbTypeConverter.cs +++ b/Rafy/Rafy/DbMigration/Providers/MySql/MySqlDbTypeConverter.cs @@ -34,6 +34,7 @@ private MySqlDbTypeConverter() { } /// /// 把 DbType的类型值 转换为 MySql 数据库中兼容的数据类型 + /// MySql数据精度 http://qimo601.iteye.com/blog/1622368 /// /// 字段的DbType类型值 /// 数据类型的长度 @@ -63,13 +64,12 @@ public override string ConvertToDatabaseTypeName(DbType fieldType, string length case DbType.UInt64: case DbType.Int64: return "BIGINT"; - case DbType.DateTimeOffset: - return "TIMESTAMP"; case DbType.Time: return "TIME"; case DbType.Date: return "DATE"; case DbType.DateTime: + case DbType.DateTimeOffset: return "DATETIME"; case DbType.Single: return "FLOAT"; @@ -131,7 +131,7 @@ public override DbType ConvertToDbType(string databaseTypeName) } if (string.Compare(databaseTypeName, "TIME", true) == 0) { return DbType.Time; } if (string.Compare(databaseTypeName, "DATETIME", true) == 0) { return DbType.DateTime; } - if (string.Compare(databaseTypeName, "TIMESTAMP", true) == 0) { return DbType.DateTimeOffset; } + if (string.Compare(databaseTypeName, "TIMESTAMP", true) == 0) { return DbType.DateTime; } } if (TypeContains(databaseTypeName, "DATE")) { return DbType.Date; } @@ -158,6 +158,10 @@ public override object ToDbParameterValue(object value) { value = TypeHelper.CoerceValue(typeof(int), value); } + else if (value is DateTimeOffset) + { + value = ((DateTimeOffset)value).DateTime; + } } return value; @@ -178,6 +182,23 @@ public override object ToClrValue(object dbValue, Type clrType) dbValue = string.Empty;//null 转换为空字符串 } + // DateTime to DateTimeOffset + // https://msdn.microsoft.com/zh-cn/library/bb546101.aspx + // DateTime DateTime2 区别 http://www.studyofnet.com/news/1050.html + if (clrType == typeof(DateTimeOffset) && dbValue != null) + { + DateTime dateTime = (DateTime)dbValue; + + if (dateTime == DateTime.MinValue) + { + dbValue = DateTimeOffset.MinValue; + } + else + { + dbValue = (DateTimeOffset)DateTime.SpecifyKind(dateTime, DateTimeKind.Local); + } + } + return dbValue; } diff --git a/Rafy/Rafy/DbMigration/Providers/Oracle/OracleDbTypeConverter.cs b/Rafy/Rafy/DbMigration/Providers/Oracle/OracleDbTypeConverter.cs index 9bf1027af..b8c95d699 100644 --- a/Rafy/Rafy/DbMigration/Providers/Oracle/OracleDbTypeConverter.cs +++ b/Rafy/Rafy/DbMigration/Providers/Oracle/OracleDbTypeConverter.cs @@ -120,7 +120,7 @@ public override DbType ConvertToDbType(string databaseTypeName) /// public override DbType FromClrType(Type clrType) { - if (clrType == typeof(DateTime)) { return DbType.Date; } + if (clrType == typeof(DateTime) || clrType == typeof(DateTimeOffset)) { return DbType.Date; } var value = base.FromClrType(clrType); @@ -153,6 +153,10 @@ public override object ToDbParameterValue(object value) { value = TypeHelper.CoerceValue(typeof(int), value); } + else if (value is DateTimeOffset) + { + value = ((DateTimeOffset)value).DateTime; + } } return value; @@ -174,6 +178,19 @@ public override object ToClrValue(object dbValue, Type clrType) { dbValue = dbValue.ToString() == "1" ? true : false; } + else if (clrType == typeof(DateTimeOffset)) + { + DateTime dateTime = (DateTime)dbValue; + + if (dateTime == DateTime.MinValue) + { + dbValue = DateTimeOffset.MinValue; + } + else + { + dbValue = (DateTimeOffset)DateTime.SpecifyKind(dateTime, DateTimeKind.Local); + } + } } else { diff --git a/Rafy/Rafy/DbMigration/Providers/SqlServer/SqlServerDbTypeConverter.cs b/Rafy/Rafy/DbMigration/Providers/SqlServer/SqlServerDbTypeConverter.cs index 329fdc8d7..889311584 100644 --- a/Rafy/Rafy/DbMigration/Providers/SqlServer/SqlServerDbTypeConverter.cs +++ b/Rafy/Rafy/DbMigration/Providers/SqlServer/SqlServerDbTypeConverter.cs @@ -51,8 +51,9 @@ public override string ConvertToDatabaseTypeName(DbType fieldType, string length case DbType.Date: case DbType.Time: case DbType.DateTime: - case DbType.DateTimeOffset: return "DATETIME"; + case DbType.DateTimeOffset: + return "DATETIMEOFFSET"; case DbType.Guid: return "UNIQUEIDENTIFIER"; case DbType.Double: @@ -121,12 +122,43 @@ public override DbType ConvertToDbType(string databaseTypeName) return DbType.Byte; case "date": case "datetime": - case "datetimeoffset": case "time": return DbType.DateTime; + case "datetimeoffset": + return DbType.DateTimeOffset; default: throw new NotSupportedException($"不支持读取数据库中的列类型:{databaseTypeName}。"); } } + + /// + /// 由于不同的 DbType 映射到库中后的类型可能是相同的,所以这里需要对类型进行兼容性判断。 + /// + /// + /// + /// + internal override bool IsCompatible(DbType oldColumnType, DbType newColumnType) + { + if (oldColumnType == newColumnType) return true; + + for (int i = 0, c = CompatibleTypes.Length; i < c; i++) + { + var sameTypes = CompatibleTypes[i]; + if (sameTypes.Contains(oldColumnType) && sameTypes.Contains(newColumnType)) + { + return true; + } + } + + return base.IsCompatible(oldColumnType, newColumnType); + } + + /// + /// SqlServer DataType + /// https://technet.microsoft.com/zh-cn/library/microsoft.sqlserver.dac.model.sqldatatype(v=sql.120).aspx + /// + private static DbType[][] CompatibleTypes = new DbType[][]{ + new DbType[]{ DbType.DateTime2, DbType.DateTimeOffset } + }; } } diff --git a/Rafy/Rafy/DbMigration/Providers/SqlServerCe/SqlServerCeDbTypeConverter.cs b/Rafy/Rafy/DbMigration/Providers/SqlServerCe/SqlServerCeDbTypeConverter.cs index 7321acfbb..36bfe1ff9 100644 --- a/Rafy/Rafy/DbMigration/Providers/SqlServerCe/SqlServerCeDbTypeConverter.cs +++ b/Rafy/Rafy/DbMigration/Providers/SqlServerCe/SqlServerCeDbTypeConverter.cs @@ -49,9 +49,96 @@ public override string ConvertToDatabaseTypeName(DbType fieldType, string length return "NVARCHAR(4000)"; case DbType.Binary: return "VARBINARY(8000)"; + case DbType.DateTime2: + case DbType.DateTimeOffset: + return "DATETIME"; default: return base.ConvertToDatabaseTypeName(fieldType, length); } } + + /// + /// 将从数据库 Schema Meta 中读取出来的列的类型名称,转换为其对应的 DbType。 + /// + /// 从数据库 Schema Meta 中读取出来的列的类型名称。 + /// + /// + public override DbType ConvertToDbType(string databaseTypeName) + { + switch (databaseTypeName.ToLower()) + { + case "datetimeoffset": + case "datetime2": + case "time": + return DbType.DateTime; + default: + return base.ConvertToDbType(databaseTypeName); + } + } + + /// + /// 返回 CLR 类型默认映射的数据库的类型。 + /// + /// + /// + public override DbType FromClrType(Type clrType) + { + if (clrType == typeof(DateTimeOffset)) { return DbType.DateTime; } + + var value = base.FromClrType(clrType); + + return value; + } + + /// + /// 将指定的值转换为一个兼容数据库类型的值。 + /// 该值可用于与下层的 ADO.NET 交互。 + /// + /// + /// + public override object ToDbParameterValue(object value) + { + value = base.ToDbParameterValue(value); + + if (value != DBNull.Value) + { + if (value is DateTimeOffset) + { + value = ((DateTimeOffset)value).DateTime; + } + } + + return value; + } + + /// + /// 将指定的值转换为一个 CLR 类型的值。 + /// + /// The database value. + /// Type of the color. + /// + public override object ToClrValue(object dbValue, Type clrType) + { + dbValue = base.ToClrValue(dbValue, clrType); + + if (dbValue != null) + { + if (clrType == typeof(DateTimeOffset)) + { + DateTime dateTime = (DateTime)dbValue; + + if (dateTime == DateTime.MinValue) + { + dbValue = DateTimeOffset.MinValue; + } + else + { + dbValue = (DateTimeOffset)DateTime.SpecifyKind(dateTime, DateTimeKind.Local); + } + } + } + + return dbValue; + } } } diff --git a/Rafy/Rafy/Domain/ORM/DbMigration/CommentFinder.cs b/Rafy/Rafy/Domain/ORM/DbMigration/CommentFinder.cs index 4cae8f03c..804300e7a 100644 --- a/Rafy/Rafy/Domain/ORM/DbMigration/CommentFinder.cs +++ b/Rafy/Rafy/Domain/ORM/DbMigration/CommentFinder.cs @@ -77,13 +77,21 @@ public string TryFindComment(IManagedProperty property) // return this.TryFindComment(type.Assembly, key); //} + /// + /// 通过程序集获取对应xml文件,为设置备注做准备 + /// Assembly.CodeBase vs Assembly.Location + /// https://www.cnblogs.com/happyframework/p/3612494.html + /// + /// + /// + /// private string TryFindComment(Assembly assembly, string key) { XDocument xdoc = null; if (!_store.TryGetValue(assembly, out xdoc)) { - var assemblyPath = assembly.Location; - var xmlDocPath = Path.Combine(Path.GetDirectoryName(assemblyPath), Path.GetFileNameWithoutExtension(assemblyPath) + ".xml"); + var assemblyCodeBase = assembly.CodeBase.Replace("file:///", ""); + var xmlDocPath = Path.Combine(Path.GetDirectoryName(assemblyCodeBase), Path.GetFileNameWithoutExtension(assemblyCodeBase) + ".xml"); if (File.Exists(xmlDocPath)) { try diff --git a/Test/Rafy.UnitTest/Entities/Yacht.cs b/Test/Rafy.UnitTest/Entities/Yacht.cs index b9414e626..5360ea805 100644 --- a/Test/Rafy.UnitTest/Entities/Yacht.cs +++ b/Test/Rafy.UnitTest/Entities/Yacht.cs @@ -109,6 +109,15 @@ public decimal DecimalValue set { this.SetProperty(DecimalValueProperty, value); } } + public static readonly Property DateTimeOffsetValueProperty = P.Register(e => e.DateTimeOffsetValue); + /// + /// + /// + public DateTimeOffset? DateTimeOffsetValue + { + get { return this.GetProperty(DateTimeOffsetValueProperty); } + set { this.SetProperty(DateTimeOffsetValueProperty, value); } + } #endregion diff --git a/Test/RafyUnitTest/Rafy/DbMigrationTest.cs b/Test/RafyUnitTest/Rafy/DbMigrationTest.cs index 305eb5203..5fe55a4f4 100644 --- a/Test/RafyUnitTest/Rafy/DbMigrationTest.cs +++ b/Test/RafyUnitTest/Rafy/DbMigrationTest.cs @@ -36,6 +36,8 @@ namespace RafyUnitTest [TestClass] public class DbMigrationTest { + private static DbTypeConverter dbTypeConverter; + [ClassInitialize] public static void DbMigrationTest_ClassInitialize(TestContext context) { @@ -52,6 +54,9 @@ public static void DbMigrationTest_ClassInitialize(TestContext context) c.ResetDbVersion(); c.ResetHistory(); + + var dbProvider = DbMigrationProviderFactory.GetProvider(c.DbSetting); + dbTypeConverter = (dbProvider.CreateRunGenerator() as SqlRunGenerator).DbTypeCoverter; }; } @@ -164,7 +169,7 @@ public void DMT_CreateColumn_String() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.String)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.String)); }); } @@ -180,7 +185,7 @@ public void DMT_CreateColumn_AnsiString() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.AnsiString)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.AnsiString)); }); } @@ -196,7 +201,7 @@ public void DMT_CreateColumn_Date() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Date)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.Date)); }); } @@ -212,7 +217,7 @@ public void DMT_CreateColumn_Time() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Time)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.Time)); }); } @@ -228,7 +233,7 @@ public void DMT_CreateColumn_DateTime() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.DateTime)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.DateTime)); }); } @@ -244,7 +249,7 @@ public void DMT_CreateColumn_DateTimeOffset() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.DateTimeOffset)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.DateTimeOffset)); }); } @@ -260,7 +265,7 @@ public void DMT_CreateColumn_Int32() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Int32)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.Int32)); }); } @@ -276,7 +281,7 @@ public void DMT_CreateColumn_Int64() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Int64)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.Int64)); }); } @@ -292,7 +297,7 @@ public void DMT_CreateColumn_Double() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Double)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.Double)); }); } @@ -308,7 +313,7 @@ public void DMT_CreateColumn_Decimal() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Decimal)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.Decimal)); }); } @@ -324,7 +329,7 @@ public void DMT_CreateColumn_Binary() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Binary)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.Binary)); }); } @@ -340,7 +345,7 @@ public void DMT_CreateColumn_Boolean() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Boolean)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.Boolean)); }); } @@ -358,7 +363,7 @@ public void DMT_CreateColumn_CLOB() var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.String)); + Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.String)); }); } } @@ -398,7 +403,7 @@ public void DMT_AlterColumn_DbType_AutoMigrate() Assert.IsTrue(column != null); var p = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName).ProviderName; - Assert.IsTrue(DbTypeConverter.IsCompatible(column.DbType, DbType.Xml)); + Assert.IsTrue(dbTypeConverter.IsCompatible(column.DbType, DbType.Xml)); }); } @@ -417,7 +422,7 @@ public void DMT_AlterColumn_DbType() Assert.IsTrue(column != null); var p = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName).ProviderName; - Assert.IsTrue(DbTypeConverter.IsCompatible(column.DbType, DbType.Xml)); + Assert.IsTrue(dbTypeConverter.IsCompatible(column.DbType, DbType.Xml)); }); } @@ -437,7 +442,7 @@ public void DMT_AlterColumn_DbType_NullStringToDouble() var table = result.FindTable("Task"); var column = table.FindColumn("Name"); Assert.IsTrue(column != null); - Assert.IsTrue(DbTypeConverter.IsCompatible(column.DbType, DbType.Double)); + Assert.IsTrue(dbTypeConverter.IsCompatible(column.DbType, DbType.Double)); Assert.IsTrue(column.IsRequired); }); } diff --git a/Test/RafyUnitTest/Rafy/EntityTest.cs b/Test/RafyUnitTest/Rafy/EntityTest.cs index abd41b6fb..e10eaefdb 100644 --- a/Test/RafyUnitTest/Rafy/EntityTest.cs +++ b/Test/RafyUnitTest/Rafy/EntityTest.cs @@ -113,7 +113,7 @@ public void ET_PersistenceStatus_New_IsDirty() [TestMethod] public void ET_PersistenceStatus_New_SetNewWillResetId() { - var item = new TestUser{ Id = 111 }; + var item = new TestUser { Id = 111 }; item.PersistenceStatus = PersistenceStatus.Unchanged; item.PersistenceStatus = PersistenceStatus.New; @@ -602,6 +602,34 @@ public void ET_Property_Boolean() } } + /// + /// https://technet.microsoft.com/zh-cn/library/ms172424(v=sql.110).aspx + /// + [TestMethod] + public void ET_Property_DateTimeOffset() + { + using (var tran = RF.TransactionScope(UnitTestEntityRepositoryDataProvider.DbSettingName)) + { + Yacht car = new Yacht() + { + DateTimeOffsetValue = DateTime.Parse("1030-1-1") + }; + + if (tran.DbSetting.ProviderName.Contains("SqlServerCe")) + { + car.DateTimeOffsetValue = DateTime.Parse("1753-1-1"); + } + + var repo = RF.ResolveInstance(); + repo.Save(car); + + long id = car.Id; + var newCar = repo.GetById(id); + + Assert.AreEqual(newCar.DateTimeOffsetValue, car.DateTimeOffsetValue); + } + } + [TestMethod] public void ET_Property_Enum_ForUI() { diff --git a/Test/RafyUnitTest/Rafy/ORMTest.cs b/Test/RafyUnitTest/Rafy/ORMTest.cs index 29a36ad1e..43aa71c78 100644 --- a/Test/RafyUnitTest/Rafy/ORMTest.cs +++ b/Test/RafyUnitTest/Rafy/ORMTest.cs @@ -4791,7 +4791,7 @@ public void ORM_TableQuery_LargeInCondition() var repo = RepositoryFacade.ResolveInstance(); using (RF.TransactionScope(repo)) { - var book=new Book(); + var book = new Book(); repo.Save(book); if (!ids.Contains(book.Id)) { @@ -5390,7 +5390,9 @@ public void ORM_DbMigrate_Column_Decimal() var db = context.DatabaseMetaReader.Read(); var table = db.FindTable("Customer"); var c1 = table.FindColumn("DecimalProperty1"); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Decimal)); + var dbProvider = DbMigrationProviderFactory.GetProvider(context.DbSetting); + var dbTypeCoverter = (dbProvider.CreateRunGenerator() as SqlRunGenerator).DbTypeCoverter; + Assert.IsTrue(dbTypeCoverter.IsCompatible(c1.DbType, DbType.Decimal)); } } @@ -5402,7 +5404,9 @@ public void ORM_DbMigrate_Column_Decimal_SpecifyLength() var db = context.DatabaseMetaReader.Read(); var table = db.FindTable("Customer"); var c1 = table.FindColumn("DecimalProperty2"); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Decimal)); + var dbProvider = DbMigrationProviderFactory.GetProvider(context.DbSetting); + var dbTypeCoverter = (dbProvider.CreateRunGenerator() as SqlRunGenerator).DbTypeCoverter; + Assert.IsTrue(dbTypeCoverter.IsCompatible(c1.DbType, DbType.Decimal)); //Assert.IsTrue(c1.Length == "18,4"); } } @@ -5415,7 +5419,9 @@ public void ORM_DbMigrate_Column_Decimal_MaptoDouble() var db = context.DatabaseMetaReader.Read(); var table = db.FindTable("Customer"); var c1 = table.FindColumn("DecimalProperty3"); - Assert.IsTrue(DbTypeConverter.IsCompatible(c1.DbType, DbType.Double)); + var dbProvider = DbMigrationProviderFactory.GetProvider(context.DbSetting); + var dbTypeCoverter = (dbProvider.CreateRunGenerator() as SqlRunGenerator).DbTypeCoverter; + Assert.IsTrue(dbTypeCoverter.IsCompatible(c1.DbType, DbType.Double)); } }