.net - QueryOver Selecting DateTime throws exception -
when seek select properties subquery (as in queryover: select columns subquery) of type datetime next exception:
the type system.datetime can not assigned property of type system.int32
the code looks this:
var subquery = queryover.of<model>().where(x => x.foreignkey == someid); mainquery.selectlist(s1 => s1.selectsubquery(subquery.select(x => x.changedate)).withalias(() => mainqueryalias.changedate) .select(...) //properties mainquery mainquery.transformusing(transformers.aliastobean<mainmodel>());
where changedate of type datetime.
the exception occurs in:
var expectresultlist = mainquery.list();
when remove changedate select-list works. other properties (like type int / string subquery can selected well. think must missing conversion somewhere have no clue where.
solution:
the problem was using same subquery more 1 times selecting different values of subquery:
s1.selectsubquery(subquery.select(smth.).withalias(some alias) .selectsubquery(subquery.select(smth. else).withalias(other alias)
however after executing 1 select, somehow next select statements utilize wrong type (from prevous query?!?) current query...
the solution set .clone before every select maintain query in default state:
s1.selectsubquery(subquery.clone().select(smth.).withalias(some alias) .selectsubquery(subquery.clone().select(smth. else).withalias(other alias)
the problem was using same subquery more 1 times selecting different values of subquery:
s1.selectsubquery(subquery.select(smth.) .withalias(some alias) .selectsubquery(subquery.select(smth. else).withalias(other alias)
however after executing 1 select, somehow next select statements utilize wrong type (from prevoius query?!?) current query...
the solution set .clone
before every select maintain query in default state:
s1.selectsubquery(subquery.clone().select(smth.) .withalias(some alias) .selectsubquery(subquery.clone().select(smth. else).withalias(other alias)
lessons learned:
always utilize .clone()
if want execute same query multiple times or create separate queries!
.net nhibernate queryover
No comments:
Post a Comment