0

I implemented a Linq query in F# that uses this solution to group by multiple columns. It compiles and works half of the time but in the other half of the time the program throws a runtime type miss-match error. Sometimes the AnonymousObject seems to get an int instead of a Nullable<int>, which then causes an error.

    let q = query{
                for wh in d.Table1 do
                where (wh.Date >= vDate)
                where (wh.Date <= bDate)
                join tae in d.Table2 on
                    (wh.Table2Key = tae.key)
                let key = AnonymousObject<int,int,Nullable<int>>(wh.Table3key,wh.ProjectTableKey,tae.ProjectPhaseKey)
                where tae.ProjectPhaseKey.HasValue
                groupValBy wh key into g
                select {pkey = g.Key.Item2; lphasekey = g.Key.Item3 ; orgk = g.Key.Item1; time = g.Sum (fun x -> x.data) }
                }

How can it be, that the types change at runtime? Can anybody give me a hint? Or has an idea how to work around that?

NetMage
  • 26,163
  • 3
  • 34
  • 55
  • 1
    I created a schema that seems to match yours, but I'm not able to reproduce what you're seeing. Can you modify [this gist](https://gist.github.com/brianberns/67d574411988da8d68fe4329d7d89508) so it causes the error? – Brian Berns May 18 '21 at 19:38
  • Why not put the `where` before the `let` and have the `Item3` be `tae.ProjectPhaseKey.Value`? – NetMage May 18 '21 at 20:16

0 Answers0