连接GaussDB的M-Compatibility兼容模式数据库时,读取 datetime 类型的字段报错 返回
SqlSugar
沟通中
1
81
lgf 发布于2周前
悬赏:0 飞吻
连接GaussDB的M-Compatibility兼容模式数据库时,读取 datetime 类型的字段报错,原生连接和Npgsql连接两种方式都试了,都不行。

static void Main(string[] args)
{
InstanceFactory.CustomAssemblies = new System.Reflection.Assembly[] {
typeof(SqlSugar.GaussDBCore.GaussDBDataAdapter).Assembly };
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = SqlSugar.DbType.GaussDBNative,
ConnectionString = "连接字符串。。。。",
IsAutoCloseConnection = true,
MoreSettings = new ConnMoreSettings()
{
DatabaseModel = SqlSugar.DbType.GaussDB
},
ConfigureExternalServices = new ConfigureExternalServices()
{
AppendDataReaderTypeMappings = new List<KeyValuePair<string, CSharpDataType>>()
{
new KeyValuePair<string, CSharpDataType>("bit",CSharpDataType.@bool),
new KeyValuePair<string, CSharpDataType>("longtext",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime),
}
}
});
var list = db.Queryable<TestGaussDB>()
.Select(s => new TestGaussDB
{
test_datetime = s.test_datetime,
test_timestamp = s.test_timestamp
}).ToList();//查询所有
foreach (var item in list)
{
Console.WriteLine(item.test_datetime);
Console.WriteLine(item.test_timestamp);
}
Console.ReadLine();
}
[SugarTable("test_gaussdb")]
public class TestGaussDB
{
public int id { get; set; }
public DateTime? test_datetime { get; set; }
public DateTime? test_timestamp { get; set; }
}DROP TABLE IF EXISTS `test_gaussdb`; CREATE TABLE `test_gaussdb` ( `id` integer NOT NULL, `test_datetime` datetime, `test_timestamp` timestamp(0), ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci WITH (storage_type=USTORE); ALTER TABLE `jiyun_framework`.`test_gaussdb` ADD CONSTRAINT `test_gaussdb_pkey` PRIMARY KEY (`id`);
热忱回答(1)
-
fate sta VIP0
2周前`test_timestamp`timestamp用时间戳类型替代datetime呢。
0 回复