Ooops, forget the text after my signature (RP)! On Apr 14, 4:53 pm, Ricardo Peres <[email protected]> wrote: > Hello, Vahid! > > Yes, I know... the problem is that Value is not a nullable type; what > happens is that there are no elements to sum, the same happens when > using SQL: "SELECT SUM(Value) FROM AnalogicalValue WHERE 1 = 2" > returns NULL. > > I solved my problem with: > > Object result = session.CreateQuery("select sum(a.Value) from > AnalogicalValue a").UniqueResult(); > Int32 sum = result is Int32 ? (Int32) result : 0; > > RP > > session.CreateQuery("select sum(a.Value) from AnalogicalValue > a").SetParameter("anmid", (Int32) > AnalogicalElementMeasure.ActivePower).UniqueResult(); > > On Apr 14, 4:42 pm, Vahid <[email protected]> wrote: > > > > > > > > > Hello, > > This is the definition of Sum method here: > > public static ***TResult*** Sum<TSource>( > > this IQueryable<TSource> source, > > Expression<Func<TSource, ***TResult***>> selector) > > > As you can see "TResult" defines the return type of the method based > > on the result of the applying a lambda-expression which is TResult > > too. > > Now try queries like this : (the same rule applies to EF and LINQ to > > SQL) > > var sum = ....Where(t=>...) > > .Sum(t=>(decimal?)t.Value)??0; //using nullable types
-- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
