本文介绍了nhibernate标准 - 表名有双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用流利的NHibernate。
我有一个标准查询,看起来像这样 - $ / b>

  var query = DetachedCriteria 
.For< table2> ;()
.SetProjection(Projections.Distinct(Projections.Property(id)))
//.Add(Restrictions.Between(\"date_field,startDate,endDate))
.Add(Restrictions.Eq(id,204010));

Add(Subqueries.In(id,query));

这个错误与错误 -

<$
Message =无法执行查询


$ b $ NHibernate.ADOException未处理b

我查看了查询并试图运行它,但也出错了。然后我注意到,在子查询中,table2的表名在引号中。我删除了这些引号,查询运行良好。
有没有人知道我可以摆脱在我的标准报价?

感谢您的任何想法


I am using Fluent NHibernate in my application.I have a criteria query that looks like this -

var query = DetachedCriteria
                .For<table2>()
                .SetProjection(Projections.Distinct(Projections.Property("id")))
                //.Add(Restrictions.Between("date_field", startDate, endDate))
                .Add(Restrictions.Eq("id", 204010));

            Add(Subqueries.In("id", query));

This errors out with the error -

NHibernate.ADOException was unhandled
Message=could not execute query

I looked at the query and tried to run it, but it also errored out. I then noticed that in the subquery, the table name for table2 is in quotes. I removed these quotes and the query ran fine.Does anyone know how I can get rid of the quotes in my criteria?

thanks for any thoughts

解决方案

I found the answer - I had my entities set up to have capital first letters, but in the database they don't have caps. The quotes in the table name make the RDBMS look at the table names with case sensitivity. So I changed my entities to be all lower case, and the query works. Thanks

这篇关于nhibernate标准 - 表名有双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 23:04