I have an outdated application (vfp 8) in which I need to extract data from (without inserts). I use the Accnum field as the primary key, it is defined in the table as symbol 11.
Factory Configuration:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <reflection-optimizer use="false" /> <session-factory> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.GenericDialect</property> <property name="connection.driver_class">NHibernate.Driver.OleDbDriver</property> <property name="connection.connection_string">Provider=VFPOLEDB.1;Data Source=C:\Analysis\Quantium\development\RD warehouse\_RDAUWH\Data;Collating Sequence=MACHINE</property> <property name="show_sql">false</property> </session-factory> </hibernate-configuration>
This is my mapping file:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="RDLabels" namespace="RDLabels.Domain"> <class name="CustMast"> <id name="Accnum" column="Accnum" type="string"> <generator class="assigned"/> </id> <property name="Fullname" /> <property name="Add" /> <property name="State" /> </class> </hibernate-mapping>
Grade:
public class CustMast { private string _accnum; public virtual string Accnum { get { return _accnum; } set { _accnum = value; } } private string _fullname; public virtual string Fullname { get { return _fullname; } set { _fullname = value; } } private string _add; public virtual string Add { get { return _add; } set { _add = value; } } private string _state; public virtual string State { get { return _state; } set { _state = value; } } }
Here is the code that gets the entry:
public CustMast GetByAccnum(String accnum) { using (ISession session = NHibernateHelper.OpenSession()) { CustMast custMast = session .CreateCriteria(typeof(CustMast)) .Add(Restrictions.Eq("Accnum", accnum)) .UniqueResult<CustMast>(); return custMast; } }
Full error:
NHibernate.Exceptions.GenericADOException : could not execute query [ SELECT this_.Accnum as Accnum0_0_, this_.Fullname as Fullname0_0_, this_.Add as Add0_0_, this_.State as State0_0_ FROM CustMast this_ WHERE this_.Accnum = ? ] Name:cp0 - Value:00059337444 [SQL: SELECT this_.Accnum as Accnum0_0_, this_.Fullname as Fullname0_0_, this_.Add as Add0_0_, this_.State as State0_0_ FROM CustMast this_ WHERE this_.Accnum = ?]
The launch of NHibernate Profiler shows:
WARN: reflection-optimizer property is ignored out of application configuration file. WARN: System.IndexOutOfRangeException: Invalid index 0 for this OleDbParameterCollection with Count=0. at System.Data.OleDb.OleDbParameterCollection.RangeCheck(Int32 index) at System.Data.OleDb.OleDbParameterCollection.GetParameter(Int32 index) at System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item(Int32 index) at NHibernate.Driver.DriverBase.ExpandQueryParameters(IDbCommand cmd, SqlString sqlString) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Driver\DriverBase.cs:line 235 at NHibernate.AdoNet.AbstractBatcher.ExpandQueryParameters(IDbCommand cmd, SqlString sqlString) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\AdoNet\AbstractBatcher.cs:line 232 at NHibernate.Loader.Loader.PrepareQueryCommand(QueryParameters queryParameters, Boolean scroll, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:line 1152 ERROR: Invalid index 0 for this OleDbParameterCollection with Count=0.