Hi,
The code i have to work with, was written by a guy who is not at the company anymore so i hope this isnt to basic to ask for.
What i Want:
I want to query a Table for all Records Containing a NULL Value in a specific nvarchar field ( called "Number"). But when i go for it entering the method which sets up the criteria i get not a single record back. if i try it with an empty string, i get some result.. but absolutley not what i want. I Get Records with the Number field containing String values like "10" or "11".
the Methods for the criteria setup look like this:
I step into the first method when in debug mode, the hashtable contains the
key, value: "Number",null or "Number",""
no sortorder or maxresult set
Code:
public override System.Collections.IList Search(Type type, System.Collections.Hashtable Properties, System.Collections.Hashtable SortOrder, int MaxResults) {
try
{
NHibernate.ISession _s = NHibernateHttpModule.CurrentSession;
ICriteria crit = _s.CreateCriteria(type);
// set the criterias
foreach (object key in Properties.Keys)
{
object val = Properties[key];
if (Properties[key] is string)
{
val = Properties[key].ToString();
if (!val.ToString().Contains("%")) val = string.Format("%{0}%", val);
}
crit.Add(Expression.Like(key.ToString(), val));
}
// set sort order
foreach (object key in SortOrder.Keys)
{
crit.AddOrder(new Order(key.ToString(), (bool)SortOrder[key]));
}
// set maxresults
if (MaxResults > 0)
{
crit.SetMaxResults(MaxResults);
}
return crit.List();
}
catch (Exception ex) {
throw ex;
}
}
public override System.Collections.IList Search(Type type, System.Collections.Hashtable Properties)
{
try
{
NHibernate.ISession _s = NHibernateHttpModule.CurrentSession;
ICriteria crit = _s.CreateCriteria(type);
foreach (object key in Properties.Keys)
{
crit.Add(Expression.Like(key.ToString(), Properties[key]));
}
return crit.List();
}
catch (Exception ex)
{
throw ex;
}
}
public override System.Collections.IList Search(Type type, string PropertyName, object PropertyValue, int MaxResults)
{
try
{
Hashtable Properties = new Hashtable();
Properties.Add(PropertyName, PropertyValue);
return this.Search(type, Properties, new Hashtable(), MaxResults);
}
catch (Exception ex)
{
throw ex;
}
}
Mapping documents:
<class name="Hobex.CRM.Invoice, Hobex.CRM.Models" table="TerminalInvoice">
<id name="Id" type="Int32" column="TerminalInvoiceID" access="field.pascalcase-m-underscore">
<generator class="identity" />
</id>
<property name="Number" column="InvoiceNumber" type="String" />
<property name="State" column="InvoiceStatusID" type="Int32" />
<property name="CreateDate" column="CreateDate" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<property name="CreateUser" column="CreateUser" type="String" />
<property name="ModifyDate" column="ModifyDate" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<property name="ModifyUser" column="ModifyUser" type="String" />
<property name="IntendedPurposeLineOne" column="IntendedPurpose1" type="String" />
<property name="IntendedPurposeLineTwo" column="IntendedPurpose2" type="String" />
<property name="IntendedPurposeLineThree" column="IntendedPurpose3" type="String" />
<property name="Information" column="InfoText" type="String" />
<property name="EnquiryDate" column="EnquiryDate" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<property name="Expenses" column="Spesen" type="Decimal" />
<property name="Amount" column="Amount" type="Decimal" />
<property name="Date" column="InvoiceDate" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<property name="Generated" column="Generated" type="Boolean"/>
<property name="Deposited" column="Deposited" type="Boolean"/>
<property name="CalculateTax" column="CalculateTax" type="Boolean"/>
<property name="Link" column="Link" type="String" />
<property name="DateFrom" column="DateFrom" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<property name="DateTo" column="DateTo" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
<many-to-one name="Member" column="MemberID" class="Hobex.CRM.Member, Hobex.CRM.Models" />
<many-to-one name="Terminal" column="TerminalID" class="Hobex.CRM.Terminal, Hobex.CRM.Models"/>
<many-to-one name="Kind" column="InvoiceKindID" class="Hobex.CRM.InvoiceKind, Hobex.CRM.Models" />
<many-to-one name="Tax" column="UstId" class="Hobex.CRM.Tax, Hobex.CRM.Models" />
<bag name="Details">
<key column="TerminalInvoiceId" />
<one-to-many class="Hobex.CRM.InvoiceDetails, Hobex.CRM.Models" />
</bag>
</class>
Name and version of the database you are using:
MS Sql Server 2005
Thanks in advance
AS