Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xugu虚谷数据库date类型字段映射错误 #1942

Open
cfires opened this issue Dec 5, 2024 · 10 comments
Open

xugu虚谷数据库date类型字段映射错误 #1942

cfires opened this issue Dec 5, 2024 · 10 comments

Comments

@cfires
Copy link

cfires commented Dec 5, 2024

问题描述及重现代码:

代码中使用DbType标记类型为date,映射查询出来统一为当前时间,并不是数据库保存的出生日期信息

  /// <summary>
  /// 出生日期
  /// </summary>
  [Description("出生日期")]
  [Column(Name = "CSRQ", DbType = "date")]
  public DateTime Csrq { get; set; }

数据库版本

xugu11

安装的Nuget包

FreeSql.All 3.5.101

.net framework/. net core? 及具体版本

.Net8

@2881099
Copy link
Collaborator

2881099 commented Dec 5, 2024

fsql.Ado.AuditDataReader += (s, e) => {

//debugger 一下 e.GetValue(x)
};

@cfires
Copy link
Author

cfires commented Dec 5, 2024

fsql.Ado.AuditDataReader += (s, e) => {

//debugger 一下 e.GetValue(x) };

{
DataReader = XuguClient.XGDataReader,
Property = System.DateTime Csrq,
Value = {2024/12/5 18:07:29}
}

value值不正确

@cfires
Copy link
Author

cfires commented Dec 5, 2024

DateTime类型的列可以正常映射,Date类型的不可以

@2881099
Copy link
Collaborator

2881099 commented Dec 5, 2024

date 就用 string 映射吧

@2881099
Copy link
Collaborator

2881099 commented Dec 5, 2024

可以研究一下 TypeHandler 文档,定义一个专属类型和 date 映射也可以的。

class XuguDate
{

}

@cfires
Copy link
Author

cfires commented Dec 6, 2024

date 就用 string 映射吧

试了试用string映射也不行

@cfires
Copy link
Author

cfires commented Dec 6, 2024

可以研究一下 TypeHandler 文档,定义一个专属类型和 date 映射也可以的。

class XuguDate {

}

class Student
{
///


/// 出生日期
///

[Description("出生日期")]
[Column(Name = "CSRQ", DbType = "date")]
public DateOnly Csrq { get; set; }
}

class DateOnlyTypeHandler : TypeHandler
{
public override object Serialize(DateOnly value) => value.ToString("yyyy-MM-dd");
public override DateOnly Deserialize(object value) => DateOnly.TryParse(string.Concat(value), out var trydo) ? trydo : DateOnly.MinValue;
public override void FluentApi(ColumnFluent col) => col.MapType(typeof(string)).StringLength(12);
}

FreeSql.Internal.Utils.TypeHandlers.TryAdd(typeof(DateOnly), new DateOnlyTypeHandler());

是这样写吗?没效果呢

@2881099
Copy link
Collaborator

2881099 commented Dec 6, 2024

数据库实际是什么类型?

@cfires
Copy link
Author

cfires commented Dec 6, 2024

数据库实际是什么类型?

date

@2881099
Copy link
Collaborator

2881099 commented Dec 6, 2024

如果方便就提供一个 .net demo + xugu 远程环境

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants