Hi there,

I am facing an issue, where I am using fluent nhibernate to call a stored 
procedure which returns the data from two tables based on join. I want a 
custom class same ProcResult.cs which contains the resulting columns as 
properties like:

 public class ProcResult
    {
        public virtual int ID { get; set; }
        public virtual string Name { get; set; }
        public virtual string Price { get; set; }
        public virtual int AddressID { get; set; }      
        public virtual string Address { get; set; }
        public virtual string Pincode { get; set; }
    }

The columns in thus class are the columns in following two tables:

public class Expediads {
        public virtual int ID { get; set; }
        public virtual string Name { get; set; }
        public virtual string Price { get; set; }
        public virtual int AddressID { get; set; }
    } 

and 

public class Adresses {
        public virtual int ID { get; set; }
        public virtual string Address { get; set; }
        public virtual string Pincode { get; set; }
    }
}
The mapping classes for the two tables are:

public class AdressesMap : ClassMap<Adresses> {
        
        public AdressesMap() {
Schema("test"); 
            Id(x => x.ID).GeneratedBy.Identity().Column("ID"); ;
            Map(x => x.Address).Column("Address");
Map(x => x.Pincode).Column("Pincode");
        }
    }
and for expediads class its:

public class ExpediadsMap : ClassMap<Expediads> {        
        public ExpediadsMap() {

Table("expediads");
Id(x => x.ID).GeneratedBy.Identity().Column("ID");
Map(x => x.Name).Column("Name");
Map(x => x.Price).Column("Price");
            Map(x => x.AddressID).Column("AddressID");
        }      
    }.

The hbm file for the proc is :

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TestHBN">  
  <sql-query name="testProc">
    <return alias="PR" class="TestHBN.Models.ProcResult, TestHBN">
      <return-property name="ID" column="ID"/>
      <return-property name="Name" column="Name" />
      <return-property name="Price" column="Price" />
      <return-property name="AddressID" column="AddressID" />
      <return-property  name="address" column="address" />
      <return-property  name="pincode" column="pincode" />
    </return>
    Call testProc;
  </sql-query>
</hibernate-mapping>

The ProcResultMap class is also defined:

public ProcResultMap()
{
            Id(x => x.ID);
            Map(x => x.Name);
            Map(x => x.Price);
            Map(x => x.AddressID);            
            Map(x => x.Address);
            Map(x => x.Pincode);
}


I am querying the stored procedure like:
using (var session = NHibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {                   
                    var list = session.GetNamedQuery("testProc").List();   
                  
                    ViewBag.List1 = list;
                }
            }
I get the following error:

*Could not find specified column in results: Address2_0_*
*
*
*Stack Trace:*
*
*
   at MySql.Data.MySqlClient.ResultSet.GetOrdinal(String name)
   at MySql.Data.MySqlClient.MySqlDataReader.GetOrdinal(String name)
   at NHibernate.Driver.NHybridDataReader.GetOrdinal(String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
   at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] 
names, ISessionImplementor session, Object owner)
   at NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, 
ISessionImplementor session, Object owner)
   at 
NHibernate.Persister.Entity.AbstractEntityPersister.Hydrate(IDataReader rs, 
Object id, Object obj, ILoadable rootLoadable, String[][] 
suffixedPropertyColumns, Boolean allProperties, ISessionImplementor session)
   at NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, 
Object obj, String instanceClass, EntityKey key, String rowIdAlias, 
LockMode lockMode, ILoadable rootPersister, ISessionImplementor session)
   at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 
i, ILoadable persister, EntityKey key, LockMode lockMode, String 
rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList 
hydratedObjects, ISessionImplementor session)
   at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] 
persisters, EntityKey[] keys, Object optionalObject, EntityKey 
optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, 
ISessionImplementor session)
   at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, 
ISessionImplementor session, QueryParameters queryParameters, LockMode[] 
lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, 
EntityKey[] keys, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, 
QueryParameters queryParameters, Boolean returnProxies)
   at 
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor
 
session, QueryParameters queryParameters, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoList(ISessionImplementor session, 
QueryParameters queryParameters)

Please help. I dnt wanna use Join() in nHibernate I was a separate custome 
class to hold trhe resultset of the stored procedure.

Thanks in advance
Akshay (Ricky)



-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fluent-nhibernate+unsubscr...@googlegroups.com.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to