I have a lot of problems getting named queries to work with nHibernate. My last problem is getting the error "request cannot be completed" without additional information. Are there any complete examples that I can download from somewhere, because all the sample tutorials and documentation provide snippets of code, but only half the story about how to make it work.
Here is the code that gives me problems.
Class
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Model.Entities { public class TableInfo { public string TABLENAME { get; set; } public string COLUMNNAME { get; set; } #region Overrides public override int GetHashCode() { int result = TABLENAME.GetHashCode(); result += COLUMNNAME.GetHashCode(); return result; } public override bool Equals(object obj) { if (obj == null) return false; TableInfo dict = (TableInfo)obj; return dict.TABLENAME.IsEqual(this.TABLENAME) && dict.COLUMNNAME.IsEqual(this.COLUMNNAME); } #endregion } }
Mapping file
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Model.Entities" assembly="Model" default-lazy="false"> <class name="Model.Entities.TableInfo, Model" table="UIM_TableColumnInfo"> <composite-id> <key-property name="TABLENAME" column="TABLENAME" type="string"></key-property> <key-property name="COLUMNNAME" column="COLUMNNAME" type="string"></key-property> </composite-id> </class> <sql-query name="GetTableInfo"> <return alias="tableInfo" class="Model.Entities.TableInfo, Model"> <return-property name="TABLENAME" column="TABLENAME"/> <return-property name="COLUMNNAME" column="COLUMNNAME"/> </return> <![CDATA[ select info.tci_table_name TABLENAME , info.tci_column_name COLUMNNAME from ALL_TAB_COLS c ,( select 'DATE' TYPE_NAME, 'D' data_type_ind from dual union select 'NUMBER','N' from dual union select 'VARCHAR2','S' from dual ) ct , UIM_TableColumnInfo info where c.DATA_TYPE = ct.TYPE_NAME (+) and c.column_id is not null and UPPER(c.TABLE_NAME) = :TableName and UPPER(c.COLUMN_NAME) = UPPER(info.tci_column_name (+)) order by c.column_id ]]> </sql-query> </hibernate-mapping>
Call code
public List<TableInfo> GetTableInfo(string tableName) { return m_TableInfoRepository .NamedQuery("GetTableInfo") .SetString("TableName", tableName) .List<TableInfo>() as List<TableInfo>; }
source share