Using FluentNhibernate 1.3.0.0, NHibernate 3.3.1.4000 on a DB2 LUW 9.7 database.
I want to get some distinct data from only one table / entity. In SQL, it´s easy:
select distinct Corporation, CalculationDate, ValuationRule
from MySchema.MyTable
where State == 0
Now, i´m trying to get those data using Linq, but it won´t work...
First try using select:
var result = Session.Query<MyEntity>()
.Where( x => x.State == State.Pending)
.Select(
x =>
new
{
Corporation = x.Corporation,
CalculationDate = x.CalculationDate,
ValuationRule = x.ValuationRule,
}).Distinct().ToList();
Resulting exception: Expression type 'NhDistinctExpression' is not supported by this SelectClauseVisitor.
Second try, using Groupby and only getting the keys:
var result = Session.Query<MyEntity>()
.Where( x => x.State == State.Pending)
.GroupBy(
x =>
new
{
Corporation = x.Corporation,
CalculationDate = x.CalculationDate,
ValuationRule = x.ValuationRule,
}).Select( x => x.Key).ToList();
Resulting Exception: "Could not execute Query". Complaining about another field "Model" missing in the group by clause that is stated in the select term. This is totally confusing me, as the specified field exists in the table but i dont want to use that field in that use case...
What is it i am missing?