我正在尝试使用SQL函数CONSTAINS
来过滤QueryOver API上的一些数据.
主要问题是我不能SqlFunction
在where子句中使用,它不能编译,因为ICriterion
需要a.
var result = Session.QueryOver<Individual>()
.Where(Projections.SqlFunction(
"FullTextContains", NHibernateUtil.Boolean,
Projections.Property<Individual>(x => x.LastName),
Projections.Constant("something")))
.List();
Run Code Online (Sandbox Code Playgroud)
我试图将它与TRUE
常量匹配,但是当执行查询时它会生成语法错误,因为CONSTAINS
函数不能与equals运算符一起使用.
var result = Session.QueryOver<Individual>()
.Where(Restrictions.Eq(Projections.SqlFunction(
"FullTextContains", NHibernateUtil.Boolean,
Projections.Property<Individual>(p => p.LastName),
Projections.Constant("something")), true))
.List();
Run Code Online (Sandbox Code Playgroud)
如何在QueryOver API的 where表达式中直接使用布尔sql函数?
可以说我们有以下型号:
public class ReadingOrder
{
public virtual int Id { get; set; }
public virtual Order Order { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
制图:
Table("db_ReadingOrder");
Id(o => o.Id).Column("Id").GeneratedBy.Identity();
References(o => o.Order, "OrderId");
Run Code Online (Sandbox Code Playgroud)
我想获得ReadingOrder
它具有orderId
与1(例如)相等.但是当我尝试a时FirstOrDefault
,查询返回null:
var readingO = _repositoryFactory.GetRepository<ReadingOrder>().FirstOrDefault(xz => xz.Order.Id == 1);
Run Code Online (Sandbox Code Playgroud)
如果我得到所有这些并在申请FirstOrDefault
作品后,但它的愚蠢:
var readingOrderList1 = _repositoryFactory.GetRepository<ReadingOrder>()
.GetAll().FirstOrDefault(xz => xz.Order.Id == 1);
Run Code Online (Sandbox Code Playgroud)
存储库中的方法具有以下格式:
public T FirstOrDefault(Expression<Func<T, bool>> predicate)
{
return _session.Query<T>().FirstOrDefault(predicate);
}
Run Code Online (Sandbox Code Playgroud)
简单的东西,但不工作.如果我去寻找一个正常的房产,那么Id
一切都按预期进行.此外,如果我从日志中获取生成的查询并将其放在sqlite中,它将成功运行并返回读取顺序.NHibernate有错误吗?是映射问题吗?或者是SQLite的问题?
有人可以解释为什么MsSql2012Dialect上的NHibernate生成服务器无法处理的查询吗?当没有明确指定排序时,它将以这种方式构建查询。
...
ORDER BY CURRENT_TIMESTAMP
OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY
Run Code Online (Sandbox Code Playgroud) 我在使用Hibernate Spatial和PostGIS时遇到问题.我有一个像这样的字段的实体:
public class LocationBean {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Type(type = "org.hibernate.spatial.GeometryType")
private Point location;
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是我无法从数据库中加载任何这些实体,除非该实体的location为null.如果它不为null,我会收到以下错误:
Exception: Can't convert object of type org.postgresql.util.PGobject
javax.el.ELException: /protected/topPanel/searchBar.xhtml @27,57 completeMethod="#{toppanelbb.completeSearchBar}": java.lang.IllegalArgumentException: Can't convert object of type org.postgresql.util.PGobject
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
at org.primefaces.component.autocomplete.AutoComplete.broadcast(AutoComplete.java:337)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:253)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at …
Run Code Online (Sandbox Code Playgroud) nhibernate ×3
sql-server ×2
c# ×1
hibernate ×1
jpa ×1
pagination ×1
postgis ×1
postgresql ×1
queryover ×1