Hi all i need some ideas how to fix order by map element issue with nullable items.
I am trying to do sorting
IQueryable<Device> q;
q = from d in q
orderby d.Attributes[1]
orderby d.Name
select d; //<-- return only devices where device_attrib_value (d.Attributes[1])
//not null
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.
The question: How can i change linq expression or mapping to provide good attribute sorting? I need it for dynamic columns in my grid with sorting and filtering
Appreciate for any help or ideas!
Database
Mapping file
< class name="Device" table="DEVICES" lazy="false">
<id name="Id">
<column name="ID" />
<generator class="native" />
</id>
<property name="Name" column="NAME"/>
<map name="Attributes" table="DEVICE_ATTRIB_VALUES">
<key column="DEVICE_ID" not-null="true"/>
<index column="ATTRIB_ID" type="System.Int64" />
<element column="VALUE" type="System.String"/>
</map>
</class>
Device entity class
public class Device
{
public virtual long Id { get; set; }
public virtual string Name { get; set; }
public virtual IDictionary<long, string> Attributes { get; set; }
}
Sql generated by NHibernate
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;