-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
157 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
<Project> | ||
<Project> | ||
<PropertyGroup> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<Authors>LiuliuSoft</Authors> | ||
<Company>柳柳软件(66soft.net)</Company> | ||
<Copyright>Copyright @ 66SOFT 2014-2020</Copyright> | ||
<Company>柳柳软件(liuliusoft)</Company> | ||
<Copyright>Copyright (c) 2014-2020 LIULIUSOFT. All rights reserved.</Copyright> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<PackageProjectUrl>https://github.com/i66soft/osharp</PackageProjectUrl> | ||
<PackageIconUrl>https://en.gravatar.com/userimage/140788132/0ff3b1e68fa0154337b1528c4276e276.png?size=80</PackageIconUrl> | ||
<RepositoryUrl>https://github.com/i66soft/osharp.git</RepositoryUrl> | ||
<PackageProjectUrl>https://github.com/dotnetcore/osharp</PackageProjectUrl> | ||
<PackageReleaseNotes>https://github.com/dotnetcore/osharp/releases</PackageReleaseNotes> | ||
<PackageIconUrl>https://en.gravatar.com/userimage/140788132/0ff3b1e68fa0154337b1528c4276e276.png?size=128</PackageIconUrl> | ||
<RepositoryUrl>https://github.com/dotnetcore/osharp</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageTags>osharp osharpns</PackageTags> | ||
<NeutralLanguage>zh-CHS</NeutralLanguage> | ||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)OSharp.Keys.snk</AssemblyOriginatorKeyFile> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...igrations/20200825153425_Init.Designer.cs → ...igrations/20200826162104_Init.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/OSharp.EntityFrameworkCore/EntityDateTimeUtcConversion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="EntityDateTimeUtcConversion.cs" company="OSharp开源团队"> | ||
// Copyright (c) 2014-2020 OSharp. All rights reserved. | ||
// </copyright> | ||
// <site>http://www.osharp.org</site> | ||
// <last-editor>郭明锋</last-editor> | ||
// <last-date>2020-08-26 23:44</last-date> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
|
||
|
||
namespace OSharp.Entity | ||
{ | ||
/// <summary> | ||
/// 实体时间属性UTC转换器 | ||
/// </summary> | ||
/// <seealso cref="OSharp.Entity.IEntityDateTimeUtcConversion" /> | ||
public class EntityDateTimeUtcConversion : IEntityDateTimeUtcConversion | ||
{ | ||
private readonly ValueConverter<DateTime, DateTime> _dateTimeConverter; | ||
private readonly ValueConverter<DateTime?, DateTime?> _nullableDateTimeConverter; | ||
|
||
/// <summary> | ||
/// 初始化一个<see cref="EntityDateTimeUtcConversion"/>类型的新实例 | ||
/// </summary> | ||
public EntityDateTimeUtcConversion() | ||
{ | ||
_dateTimeConverter = new ValueConverter<DateTime, DateTime>( | ||
local => local.ToUniversalTime(), | ||
utc => utc.ToLocalTime()); | ||
_nullableDateTimeConverter = new ValueConverter<DateTime?, DateTime?>( | ||
local => local.HasValue ? local.Value.ToUniversalTime() : local, | ||
utc => utc.HasValue ? utc.Value.ToLocalTime() : utc); | ||
} | ||
|
||
/// <summary> | ||
/// 转换指定的实体类型。 | ||
/// </summary> | ||
/// <param name="entityType">实体类型</param> | ||
public void Convert(IMutableEntityType entityType) | ||
{ | ||
foreach (IMutableProperty property in entityType.GetProperties()) | ||
{ | ||
if (property.ClrType == typeof(DateTime)) | ||
{ | ||
property.SetValueConverter(_dateTimeConverter); | ||
} | ||
else if (property.ClrType == typeof(DateTime?)) | ||
{ | ||
property.SetValueConverter(_nullableDateTimeConverter); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/OSharp.EntityFrameworkCore/IEntityDateTimeUtcConversion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="IEntityUtcConverter.cs" company="OSharp开源团队"> | ||
// Copyright (c) 2014-2020 OSharp. All rights reserved. | ||
// </copyright> | ||
// <site>http://www.osharp.org</site> | ||
// <last-editor>郭明锋</last-editor> | ||
// <last-date>2020-08-26 23:37</last-date> | ||
// ----------------------------------------------------------------------- | ||
|
||
using Microsoft.EntityFrameworkCore.Metadata; | ||
|
||
|
||
namespace OSharp.Entity | ||
{ | ||
/// <summary> | ||
/// 实体时间属性UTC转换器 | ||
/// </summary> | ||
public interface IEntityDateTimeUtcConversion | ||
{ | ||
/// <summary> | ||
/// 转换指定的实体类型。 | ||
/// </summary> | ||
/// <param name="entityType">实体类型</param> | ||
void Convert(IMutableEntityType entityType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.