mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
add net60 DateOnly mapping SqlServer
This commit is contained in:
@ -29,7 +29,7 @@
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net60' or '$(TargetFramework)' == 'net50'">
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.1" />
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -42,5 +42,8 @@
|
||||
<PropertyGroup Condition="'$(TargetFramework)' == 'net40'">
|
||||
<DefineConstants>net40</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(TargetFramework)' == 'net60'">
|
||||
<DefineConstants>net60;microsoft</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -72,6 +72,15 @@ namespace FreeSql.SqlServer
|
||||
if (param.Equals(DateTimeOffset.MinValue) == true) param = new DateTimeOffset(new DateTime(1970, 1, 1), TimeSpan.Zero);
|
||||
return string.Concat("'", ((DateTimeOffset)param).ToString("yyyy-MM-dd HH:mm:ss.fff zzzz"), "'");
|
||||
}
|
||||
#if net60
|
||||
else if (param is DateOnly || param is DateOnly?)
|
||||
{
|
||||
if (param.Equals(DateOnly.MinValue) == true) param = new DateOnly(1970, 1, 1);
|
||||
return string.Concat("'", ((DateOnly)param).ToString("yyyy-MM-dd"), "'");
|
||||
}
|
||||
else if (param is TimeOnly || param is TimeOnly?)
|
||||
return ((TimeOnly)param).ToTimeSpan().TotalSeconds;
|
||||
#endif
|
||||
else if (param is TimeSpan || param is TimeSpan?)
|
||||
return ((TimeSpan)param).TotalSeconds;
|
||||
else if (param is byte[])
|
||||
|
@ -37,6 +37,9 @@ namespace FreeSql.SqlServer
|
||||
{ typeof(TimeSpan).FullName, CsToDb.New(SqlDbType.Time, "time","time NOT NULL", false, false, 0) },{ typeof(TimeSpan?).FullName, CsToDb.New(SqlDbType.Time, "time", "time",false, true, null) },
|
||||
{ typeof(DateTime).FullName, CsToDb.New(SqlDbType.DateTime, "datetime", "datetime NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTime?).FullName, CsToDb.New(SqlDbType.DateTime, "datetime", "datetime", false, true, null) },
|
||||
{ typeof(DateTimeOffset).FullName, CsToDb.New(SqlDbType.DateTimeOffset, "datetimeoffset", "datetimeoffset NOT NULL", false, false, new DateTimeOffset(new DateTime(1970,1,1), TimeSpan.Zero)) },{ typeof(DateTimeOffset?).FullName, CsToDb.New(SqlDbType.DateTimeOffset, "datetimeoffset", "datetimeoffset", false, true, null) },
|
||||
#if net60
|
||||
{ typeof(DateOnly).FullName, CsToDb.New(SqlDbType.Date, "date", "date NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateOnly?).FullName, CsToDb.New(SqlDbType.Date, "date", "date", false, true, null) },
|
||||
#endif
|
||||
|
||||
{ typeof(byte[]).FullName, CsToDb.New(SqlDbType.VarBinary, "varbinary", "varbinary(255)", false, null, new byte[0]) },
|
||||
{ typeof(string).FullName, CsToDb.New(SqlDbType.NVarChar, "nvarchar", "nvarchar(255)", false, null, "") },
|
||||
|
@ -113,6 +113,13 @@ namespace FreeSql.SqlServer
|
||||
var ts = (TimeSpan)value;
|
||||
value = $"{ts.Hours}:{ts.Minutes}:{ts.Seconds}.{ts.Milliseconds}";
|
||||
}
|
||||
#if net60
|
||||
if (type == typeof(TimeOnly) || type == typeof(TimeOnly?))
|
||||
{
|
||||
var ts = (TimeOnly)value;
|
||||
value = $"{ts.Hour}:{ts.Minute}:{ts.Second}.{ts.Millisecond}";
|
||||
}
|
||||
#endif
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}", (_orm.Ado as AdoProvider).AddslashesProcessParam(value, type, col));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user