gpt4 book ai didi

datetime - Fluent Nhibernate - 配置所有日期以从 UTC 重新水化

转载 作者:行者123 更新时间:2023-12-04 17:34:12 24 4
gpt4 key购买 nike

这个问题是关于 "Rehydrating fluent nhibernate configured DateTime as Kind Utc rather than Unspecified" .

该问题的后来答案之一是:

Map(x => x.EntryDate).CustomType<UtcDateTimeType>();

这适用于一个实体的一个属性。

我想知道是否有办法指定所有日期时间属性在数据库中存储为 UTC。

这是可能的,如果是,如何?

最佳答案

NHibernate 流畅的方式是 Convention

Conventions

James Gregory 于 2012 年 4 月 3 日编辑了此页面 · 1 次修订

...
The conventions are built using a set of interfaces and base classes that each define a single method, Apply, with varying parameters based on the kind of convention you're creating; this method is where you make the changes to the mappings.
...



草拟的例子:
public class UtcConvention : IPropertyConvention
{
public void Apply(IPropertyInstance instance)
{
if (instance.Type.Name == "Date")
{
instance.CustomType<UtcDateTimeType>();
}
}
}

我们必须将其添加到配置中
FluentMappings
.Conventions.Add(new UtcConvention())

关于datetime - Fluent Nhibernate - 配置所有日期以从 UTC 重新水化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28935400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com