DotNetNext / SqlSugar

.Net aot ORM Fastest ORM Simple Easy VB.NET Sqlite orm Oracle ORM Mysql Orm 虚谷数据库 postgresql ORm SqlServer oRm 达梦 ORM 人大金仓 ORM 神通ORM C# ORM , C# ORM .NET ORM NET5 ORM .NET6 ORM ClickHouse orm QuestDb ,TDengine ORM,OceanBase orm,GaussDB orm ,Tidb orm Object/Relational Mapping
https://www.donet5.com/Home/Doc
MIT License
5.31k stars 1.33k forks source link

Insert Other Flied DateTime.Now Bug Insert => '2024-01-1613:00:00.000' #1216

Closed mrreddevil2412 closed 8 months ago

mrreddevil2412 commented 8 months ago

[ERROR Message]: Operand type clash: time is incompatible with float [TYPE]: SqlException [ERROR INFO]: Operand type clash: time is incompatible with float [ERROR LINE]: at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

image

Insert Filed "@NgayTao" ='2024/01/16 12:19:22' When Excute in SqlServer 2019 => "@NgayTao" ='2024/01/1612:19:22'

DotNetNext commented 8 months ago

This is parameterized, should not report errors, you see if the system is adjusted

DotNetNext commented 8 months ago

Maybe the data type is wrong

DotNetNext commented 8 months ago

You can test this with a 2-field table

mrreddevil2412 commented 8 months ago

I try CreateTime and NgayTao You can see in picture If no insert NgayTao => success true

mrreddevil2412 commented 8 months ago

NgayTao dataType DateTime CreateTime same DataType

The first i see this bug

mrreddevil2412 commented 8 months ago

`[SugarTable("CC_DangKy")] public class CC_DangKy_Entity { [SugarColumn(IsPrimaryKey = true, IsNullable = false)] public long Id { get; set; }

[SugarColumn(IsNullable = false)]
public int? NamThang { get; set; }

public DateTime? Ngay { get; set; }

[SugarColumn(IsNullable = false)]
public long? EmployeeId { get; set; }

[SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
public string? Ca1 { get; set; }

[SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
public string? Ca2 { get; set; }

[SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
public string? Ca3 { get; set; }

[SugarColumn(IsNullable = true)]
public int? VanPhong { get; set; }

[SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(500)")]
public string? CungDuong { get; set; }

[SugarColumn(IsNullable = true, ColumnDataType = "varchar(20)")]
public string? LoaiPhep { get; set; }

[SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(500)")]
public string? LyDo { get; set; }

/// <summary>
/// Nghỉ từ giờ
/// </summary>
[SugarColumn(IsNullable = true, ColumnDataType = "Time")]
public TimeSpan? TuGio { get; set; }

/// <summary>
/// Nghỉ đến giờ
/// </summary>
[SugarColumn(IsNullable = true, ColumnDataType = "Time")]
public TimeSpan? DenGio { get; set; }

/// <summary>
/// Số giờ nghỉ
/// </summary>
[SugarColumn(IsNullable = true, ColumnDataType = "float")]
public TimeSpan? SoGio { get; set; }

[SugarColumn(IsNullable = true,ColumnDataType ="datetime")]
public DateTime NgayTao { get; set; }

[SugarColumn(ColumnDataType = "tinyint")]
public int? TrangThai { get; set; }

/// <summary>
/// Id người duyệt
/// </summary>
public long? NguoiDuyet1 { get; set; }

[SugarColumn(IsIgnore = true)]
[Navigate(NavigateType.OneToOne, nameof(NguoiDuyet1))]
public SysAccountInfoEntity? AccNguoiDuyet1 { get; set; }

public DateTime? Duyet1Ngay { get; set; }

public long? NguoiDuyet2 { get; set; }

[SugarColumn(IsIgnore = true)]
[Navigate(NavigateType.OneToOne, nameof(Duyet2Ngay))]
public SysAccountInfoEntity? AccNguoiDuyet2 { get; set; }

public DateTime? Duyet2Ngay { get; set; }

[SugarColumn(IsNullable = true, ColumnDataType = "nvarchar(500)")]
public string PhanHoi { get; set; }

[SugarColumn(IsNullable = true)]
public DateTime CreateTime { get; set; }

}`

This class Entity

DotNetNext commented 8 months ago

[SugarColumn(IsNullable = true, ColumnDataType = "float")] public TimeSpan? SoGio { get; set; }

Change to

[SugarColumn(IsNullable = true, ColumnDataType = "time")] public TimeSpan? SoGio { get; set; }

DotNetNext commented 8 months ago

Change the database, too

mrreddevil2412 commented 8 months ago

oh, it's worked :)) many thank bro!