今天遇到的問題:
hql="select max(sninfo.ln) from sninfo",設定maxresult(1),執行這條查詢時,
返回的是sninfo物件,其中ln是519,query的返回結果集也不是1。
改為iquery q = _corerepository.activesession.createquery("select max(s.ln) from sninfo as s" );
q.uniqueresult();
發現,不能用類名修飾字段,必須用別名。
查詢nhibernate源**:
( (dialect
isdialect.mssql2000dialect) )
( (dialect
isdialect.sybasedialect) )
疑問:"in class" 和 as的功能相似?
某些函式,如lower在不同的資料庫中語法不同,在nhibernate中用發也不同,這樣還怎麼跨資料庫?
enumerable
=s.enumerable(
"select max(foo.component.importantdates.elements) from foo in class foo group by foo.id
");ienumerator enumerator
=enumerable.getenumerator();
assert.istrue( enumerator.movenext() );
assert.istrue( enumerator.current
isdatetime );
可以同過ienumerator 獲取資料,且效率比find()高
entities returned as results are initialized on demand. the first sql query returns
identifiers only. so enumerator()is usually a less efficient way to retrieve
object than find()
呼叫例子:
enumerable
=s.enumerable(
"select count(foo) from foo in class foo where foo.id=?",
foo.key, nhibernateutil.string );
the query string
第二個引數:a value to be written to a "?" placeholder in the query string代替?佔位符的值
第三個:the hibernate type of the value
後面兩個引數會組合成queryparameters定義如下:
public queryparameters( itype[ ] positionalparametertypes, object[ ] positionalparametervalues )
NHibernate 對分組聚合支援的不好
hibernate 對分組聚合支援的不好,例如下面的 var query from raqi in session.query group raqi by raqi.spacekey into g select new 這樣的查尋生成的sql如下,很明顯是錯誤的,select factstatra0...
SQL 聚合函式 非聚合函式
聚合函式 聚合函式就是對一組值進行計算後返回單個值 即分組 聚合函式在計算時都會忽略空值 null 所有的聚合函式均為確定性函式。即任何時候使用一組相同的輸入值呼叫聚合函式執行後的返回值都是相同的,無二義性。2 聚合開窗函式 聚合函式加上 over 開窗函式就是聚合開窗函式。create table...
聚合函式的使用
sql查詢中使用in 相對於比 exists更具慢,所有一般是子查詢都用exists,子查詢裡面返回的是結果集,如果要更加精準的,那就是 前面查詢的表的某個欄位要恆等於子查詢的的某個字段 select into a from m m where exists select t.prefix from...