Have you examined the SQL queries being generated? That's usually the first 
place I look when I'm not getting the results I expect.

On Monday, November 2, 2015 at 9:55:53 AM UTC-7, [email protected] wrote:
>
> I’m having what appears to be a bizarre NHibernate failure where NH 
> _sometimes_ cannot find rows in a database. I’ve searched the 
> documentation, wiki, and net without finding anything I can recognize as a 
> hint. I apologize for the length of this but my efforts to create a small 
> reproducer have failed.
>
>
> Database table:
>
>
> CREATE TABLE [Se3OnboardSoftware]
>
>    ([ID] INTEGER not null identity(1,1),
>
>     [COMPONENT] VARCHAR(50) not null,
>
>     [MODEL] VARCHAR(50),
>
>     [VERSIONNUMBER] INTEGER not null,
>
>     [FILEPATH] VARCHAR(256),
>
>     [DATA] VARBINARY(MAX) not null,
>
> constraint PK_Se3OnboardSoftware primary key ([ID]));
>
> create index [IX_Se3OnboardSoftware_Component] on [Se3OnboardSoftware] (
> [Component]);
>
> create index [IX_Se3OnboardSoftware_VersionNumber] on [Se3OnboardSoftware] 
> ([VersionNumber]);
>
> create unique index [UX_Se3OnboardSoftware_Component_VersionNumber] on
>
>     [Se3OnboardSoftware] ([Component], [VersionNumber]);
>
>
> Mapping:
>
>
> <?xml version="1.0" encoding="utf-8" ?>
>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
>
>                    default-access="property"
>
>                    namespace="Segway.Service.Objects"
>
>                    assembly="SE3 Objects"
>
> >
>
>   <class name="Se3OnboardSoftware" table="SE3ONBOARDSOFTWARE">
>
>     <id name="ID" column="ID" >
>
>       <generator class="identity"/>
>
>     </id>
>
>     <property name="Component" column="COMPONENT" />
>
>     <property name="Model" column="MODEL" />
>
>     <property name="VersionNumber" column="VERSIONNUMBER" />
>
>     <property name="FilePath" column="FILEPATH" />
>
>     <property name="Data" type="BinaryBlob" >
>
>       <column name="DATA" sql-type="varbinary(max)" />
>
>     </property>
>
>   </class>
>
> </hibernate-mapping>
>
>
> Object (the ID property comes from the NHibernateBase parent object):
>
>
> public partial class Se3OnboardSoftware : NHibernateBase
>
> {
>
>     private String _Component;
>
>     [DataMember]
>
>     public virtual String Component
>
>     {
>
>         get { return _Component; }
>
>         set
>
>         {
>
>             _Component = value;
>
>             if ((String.IsNullOrEmpty(_Component)==false)&&( 
> _Component.Length > 50)) _Component = _Component.Substring(0, 50);
>
>         }
>
>     }
>
>
>     private string _Model;
>
>     [DataMember]
>
>     public virtual string Model
>
>     {
>
>         get { return _Model; }
>
>         set
>
>         {
>
>             if (string.IsNullOrEmpty (value) || (value.Length <= 50))
>
>             {
>
>                 _Model = value;
>
>             }
>
>             else
>
>             {
>
>                 _Model = value.Substring (0, 50);
>
>             }
>
>         }
>
>     }
>
>
>     [DataMember]
>
>     public virtual int VersionNumber { get; set; }
>
>
>     private String _FilePath;
>
>     [DataMember]
>
>     public virtual String FilePath
>
>     {
>
>         get { return _FilePath; }
>
>         set
>
>         {
>
>             _FilePath = value;
>
>             if ((String.IsNullOrEmpty(_FilePath)==false)&&( 
> _FilePath.Length > 256)) _FilePath = _FilePath.Substring(0, 256);
>
>         }
>
>     }
>
>
>     [DataMember]
>
>     public virtual Byte[] Data { get; set; }
>
> }
>
>
> And the query:
>
>
> using (ISession session = GetNHibernateSession ())
>
> {
>
>     ICriteria criteria = session.CreateCriteria<Se3OnboardSoftware> ();
>
>     IList<Se3OnboardSoftware> list = criteria.List<Se3OnboardSoftware> ();
>
>
> The apparent failure is that sometimes list winds up with seven elements 
> (the number of rows in the Se3OnboardSoftware table, the desired result), 
> and sometimes with zero. Another query:
>
>
> using (ISession session = GetNHibernateSession ())
>
> {
>
>     ICriteria criteria = session.CreateCriteria<Se3OnboardSoftware> ();
>
>     criteria.Add (Expression.Eq ("Component", software.Component));
>
>     if (!string.IsNullOrEmpty (software.Model))
>
>     {
>
>         criteria.Add (Expression.Eq ("Model", software.Model));
>
>     }
>
>     else
>
>     {
>
>         criteria.Add (Expression.Disjunction ()
>
>             .Add (Expression.IsNull ("Model"))
>
>             .Add (Expression.Eq ("Model", string.Empty)));
>
>     }
>
>     criteria.Add (Expression.Eq ("VersionNumber", 
> software.VersionNumber));
>
>     IList<Se3OnboardSoftware> list = criteria.List<Se3OnboardSoftware>();
>
>
> sometimes returns 0 elements, sometimes 1 (the correct number).
>
>
> The DATA column has about a megabyte of blob.
>
>
> Windows 7, .NET 4, NHibernate 3.1 built against .NET 3.5 configured for 
> SQL Server 2008, actual SQL Server 2014, IIS WCF service.
>
>
> So what am I doing wrong?
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to