2

是否可以转换这种查询:

SELECT field1, field2 FROM table WHERE SHA1(field1 + field2) = 'hash'; 

进入 NHibernate 的 Criteria 语言?例如,类似:

session.CreateCriteria<Car>()
    .Add(Expression.Eq("SHA1(field1 + field2)", "hash"));
4

1 回答 1

2

也许这个答案对你有用?

https://stackoverflow.com/a/797243

我会尝试类似的东西:

ISQLFunction sqlAdd = new VarArgsSQLFunction("(", "+", ")");
var concat = Projections.SqlFunction(sqlAdd, NHibernateUtil.String, Projections.Property("ObjectProperty1"), Projections.Property("ObjectProperty2"));
var sha1 = Projections.SqlFunction("SHA1", NHibernateUtil.String, concat);
...
session.CreateCriteria<Car>().Add(Expression.Eq(sha1, "hash"));
于 2012-04-26T22:21:10.240 回答