- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试在 NHibernate 4.x 中实现对 SQL Server 2016 时态表的基本支持。这个想法是改变 SQL 语句从
SELECT * FROM Table t0
到
SELECT * FROM Table FOR SYSTEM_TIME AS OF '2018-01-16 00:00:00' t0
您可以在 SQL Server 2016 中找到有关时态表的更多信息 here
不幸的是,我还没有找到任何方法来在表名及其别名之间插入 FOR FOR SYSTEM_TIME AS OF '...'
语句。我不确定自定义方言是否支持这一点。我目前唯一可行的解决方案是在额外的 WHERE
中附加 FOR SYSTEM_TIME
语句,我的输出 SQL 如下所示
SELECT * FROM Table t0 WHERE FOR SYSTEM_TIME AS OF '2018-01-16 00:00:00'=1
为此,我按如下方式实现了生成器和方言:
public static class AuditableExtensions
{
public static bool AsOf(this IAuditable entity, DateTime date)
{
return true;
}
public static IQueryable<T> Query<T>(this ISession session, DateTime asOf) where T : IAuditable
{
return session.Query<T>().Where(x => x.AsOf(asOf));
}
}
public class ForSystemTimeGenerator : BaseHqlGeneratorForMethod
{
public static readonly string ForSystemTimeAsOfString = "FOR SYSTEM_TIME AS OF";
public ForSystemTimeGenerator()
{
SupportedMethods = new[]
{
ReflectionHelper.GetMethod(() => AuditableExtensions.AsOf(null, DateTime.MinValue))
};
}
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject,
ReadOnlyCollection<Expression> arguments,
HqlTreeBuilder treeBuilder,
IHqlExpressionVisitor visitor)
{
return treeBuilder.BooleanMethodCall(nameof(AuditableExtensions.AsOf), new[]
{
visitor.Visit(arguments[1]).AsExpression()
});
}
}
public class MsSql2016Dialect : MsSql2012Dialect
{
public MsSql2016Dialect()
{
RegisterFunction(nameof(AuditableExtensions.AsOf), new SQLFunctionTemplate(
NHibernateUtil.Boolean,
$"{ForSystemTimeGenerator.ForSystemTimeAsOfString} ?1?2=1"));
}
}
任何人都可以提供任何更好的方法或示例,我可以用来继续前进并在表名及其别名之间插入 FOR SYSTEM_TIME AS OF
语句吗?目前我能看到的唯一解决方案是在 SessionInterceptor
中更改 OnPrepareStatement
中的 SQL,但我相信有一些更好的方法...
最佳答案
NHibernate Reference 5.1 中有关于使用 NHibernate 临时表的信息,地址为 NHibernate Reference
19.1 节中的示例展示了如何使用临时表:
首先定义一个过滤器:
<filter-def name="effectiveDate">
<filter-param name="asOfDate" type="date"/>
</filter-def>
然后将其附加到一个类中:
<class name="Employee" table="Employee For System_Time All" ...>
...
<many-to-one name="Department" column="dept_id" class="Department"/>
<property name="EffectiveStartDate" type="date" column="eff_start_dt"/>
<property name="EffectiveEndDate" type="date" column="eff_end_dt"/>
...
<!--
Note that this assumes non-terminal records have an eff_end_dt set to
a max db date for simplicity-sake
-->
<filter name="effectiveDate"
condition=":asOfDate BETWEEN eff_start_dt and eff_end_dt"/>
</class>
然后您需要在 session 上启用过滤器:
ISession session = ...;
session.EnableFilter("effectiveDate").SetParameter("asOfDate", DateTime.Today);
var results = session.CreateQuery("from Employee as e where e.Salary > :targetSalary")
.SetInt64("targetSalary", 1000000L)
.List<Employee>();
希望这能让人们开始。
关于c# - NHibernate HQL Generator 支持 SQL Server 2016 时态表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48280776/
我是 Julia 的新手。 我主要用python编程。 在 python 中, 如果你想迭代大量的值, 通常构造一个所谓的生成器来节省内存使用。 这是一个示例代码: def generator(N):
这个问题很奇怪。我试图直接在 build.gradle 中添加一个字符串,因为我需要它来使用 Tray 库 ( https://github.com/grandcentrix/tray )。在我的第一
我正在尝试在我的新 symfony3 项目中使用生成 CRUD 功能。我创建了一个名为 AdminBundle 的 bundle ,其中包含生成器、实体测试以及生成器,所有这些都处理得很好。我检查了我
我尝试理解生成器,但我发现了一个我无法遵循的示例。 // First Generator function* Colors () { yield "blue"; yield* MoreColo
我将制作一款完全由程序生成的空间/交易/战斗游戏。但是,我知道将整个星系的所有细节存储在内存中是不可行的。因此,我一直认为我可以使用种子来生成太阳系,并且从该太阳系,您可以使用跳跃门前往其他太阳系。问
我在 Eclipse Helios 中使用 MyBatis Generator (MyBatis Generator 1.3.1.201101032122),但每次我自动生成持久类时,生成器都会删除属
@GenerateInterface class A {} @GenerateInterface class B { void setA(IA a) {} } 我的注释处理器应该生成这些接口(in
我刚刚在一个空目录中安装了 yeoman,它打印出一个错误。这就是我所做的: npm i yo -g npm i generator-webapp -g 之后我抛出一个错误: require('yeo
我正在使用 NReco PDFGenerator 从 HTML 字符串创建 PDF 文档。当表格被分页符拆分时,表格标题与表格中的下一行重叠(见下图)。 有想法该怎么解决这个吗? 最佳答案 我发现这是
我有这个命名空间: namespace :manage do # Directs /manage/products/* to Manage::ProductsController
我有一个 Open API 3 规范的 yaml 文件,它有一些 x- 前缀的属性。我正在尝试使用 openapi-generator-cli 生成一个 Angular Typescript SDK。
我有一个返回生成器的函数。目前它使用yield from: function foo() { $generator = getGenerator(); // some other st
我选择Symfony2 docs 。据说添加 /** * @ORM\Entity(repositoryClass="Acme\StoreBundle\Entity\ProductRepository
运行命令生成新的 rails 项目: $ rails generate controller home index 以上将创建四个新的 Rails 项目:generate、controller、hom
我们实际上已经将jvm内存增加到了256M,现在老年代看起来很小,但Perm Generation相当高,接近80%。通过 jstat 捕获的示例数据如下。高永久代意味着什么? Timestamp
class Invoice def Invoice.generate(order_id, charge_amount, credited_amount = 0.0) Invoice.new
我在写 this comparison为了帮助人们理解所有这些废话,目前看来,generator-angular 的好处和值(value)只是您使用 generator-angular-fullsta
我有一个包含以下代码段的 OpenAPI 规范文档(我无法控制): servers: - url: http://www.[someservice].com/api 我正在使用这个 OpenAPI
我正在使用 openapi-yaml 将 swagger 文件转换为开放的 API v3 文件。使用 Maven 生成器。 我想做的是将新文件直接放入某个目录。 但是会生成一些我不需要的其他文件,例如
我的生成器中有以下标准文件夹结构。我当前正在努力解决的任务是我目前有一个模板化的 _package.json ,我将其写入磁盘以用于主要生成。我想在编写的 package.json 中包含一个变量,它
我是一名优秀的程序员,十分优秀!