title: nhibernate map item order issue
body: <p>Hi all i need some ideas how to fix order by map element issue with nullable items.</p>
  
  <p>I am trying to do sorting</p>
  
  <pre><code>IQueryable&lt;Device&gt; q;
  q = from d in q
  orderby d.Attributes[1]
  orderby d.Name
  select d; //&lt;-- return only devices where device_attrib_value (d.Attributes[1])
  //not null
  </code></pre>
  
  <p>The problem in result query its not return elements without device_attrib_value.If look down you can see sql i think it wrong becouse there must be some join expression. </p>
  
  <p>The question: <em>How can i change linq expression or mapping to provide good attribute sorting?</em> I need it for dynamic columns in my grid with sorting and filtering</p>
  
  <p>Appreciate for any help or ideas!</p>
  
  <p>Database</p>
  
  <p><img src="https://i.stack.imgur.com/2CpNB.png" alt="Simple database"></p>
  
  <p>Mapping file</p>
  
  <pre><code>&lt; class name="Device" table="DEVICES" lazy="false"&gt;   
      &lt;id name="Id"&gt;
        &lt;column name="ID" /&gt;
        &lt;generator class="native" /&gt;
      &lt;/id&gt;    
      &lt;property name="Name" column="NAME"/&gt;       
      &lt;map name="Attributes" table="DEVICE_ATTRIB_VALUES"&gt;
          &lt;key column="DEVICE_ID"  not-null="true"/&gt;
          &lt;index column="ATTRIB_ID" type="System.Int64" /&gt;
          &lt;element column="VALUE" type="System.String"/&gt;
      &lt;/map&gt;    
    &lt;/class&gt;
  </code></pre>
  
  <p>Device entity class</p>
  
  <pre><code>public class Device
  {        
      public virtual long Id { get; set; }
      public virtual string Name { get; set; }        
      public virtual IDictionary&lt;long, string&gt; Attributes { get; set; }        
  }
  </code></pre>
  
  <p>Sql generated by NHibernate</p>
  
  <pre><code>select
          device0_.ID as ID1_,
          device0_.NAME as NAME1_
      from
          DEVICES device0_,
          DEVICE_ATTRIB_VALUES attributes1_
      where
          device0_.ID=attributes1_.DEVICE_ID
          and attributes1_.ATTRIB_ID = @p0
      order by
          attributes1_.VALUE asc,
          device0_.NAME asc;
  </code></pre>