System.InvalidCastException: Cannot convert CLR type to JOIN type
-
mardi 1 mai 2012 15:27
We are attempting to perform a Left Anti-Semi Join in Stream Insight using a custom payload type, called CRB. It contains only primitive fields (no lists or anything special). We are seeing the InvalidCastException when attempting to do this. If we remove the LASJ, everything works fine. Here is the LASJ code.
var inputStream = this.InputQuery.ToStream<CRB>(); var filter = from record in inputStream where record.AppliedJobCode == 1556 where ( from right in inputStream where right.AppliedJobCode == 1155 select right ).IsEmpty() select record;
Once again, if we remove the LASJ (the second where clause), there are no problems with the filter. Any help or guidance is most appreciated.
Thanks,
Dave
Toutes les réponses
-
mardi 1 mai 2012 20:31
Without knowing the actual data types at play here, I'm kind of shooting in the dark. I would try decomposing the filter statement and doing a projection on the right stream so you can end up with an event to event comparison like the following:
var inputStream = this.InputQuery.ToStream<CRB>(); var leftStream = inputStream.Where(e => e.AppliedJobCode == 1556); var rightStream = from e in inputStream where e.AppliedJobCode == 1155 select new CRB { AppliedJobCode = 1556 // project other fields here }; var filter = from left in leftStream where ( from right in rightStream where left.AppliedJobCode == right.AppliedJobCode select right ).IsEmpty(); select left; -
mercredi 2 mai 2012 01:12
I did a quick mock-up of the query and types in LinqPad and ran it with no problem. Can you take a look and, perhaps, modify to better illustrate your case?
void Main() { Func<int, DateTimeOffset> t = (m) => new DateTimeOffset(2011, 1, 11, 8, 0, 0, TimeSpan.Zero).AddMinutes(m); var values = new[]{ new {Name="App 1", AppliedJobCode=1155, Timestamp = t(0)}, new {Name="App 2", AppliedJobCode=1156, Timestamp = t(0)}, new {Name="App 3", AppliedJobCode=1155, Timestamp =t(1)}, new {Name="App 4", AppliedJobCode = 1155, Timestamp=t(4)} }; var crbStream = values.ToPointStream(Application, e => PointEvent.CreateInsert(e.Timestamp, new CRB(){Name = e.Name, AppliedJobCode = e.AppliedJobCode}), new AdvanceTimeSettings( new AdvanceTimeGenerationSettings(TimeSpan.FromSeconds(1), TimeSpan.FromTicks(1)), null, AdvanceTimePolicy.Drop)); var lasj = from i in crbStream where i.AppliedJobCode == 1155 where (from j in crbStream where j.AppliedJobCode == 1156 select j).IsEmpty() select i; lasj.ToPointEnumerable().Dump(); } // Define other methods and classes here public class CRB{ public int AppliedJobCode { get; set; } public string Name { get; set; } }DevBiker (aka J Sawyer)
Microsoft MVP - Sql Server (StreamInsight)
If I answered your question, please mark as answer.
If my post was helpful, please mark as helpful. -
mercredi 2 mai 2012 02:15
Thanks all for the suggestions. We are still working through this. I'll take each reply one a time here.
TXPower125, we tried that in our app, to but still have the InvalidCastException when the filter expression is being run. The exception is exactly the same, except for the number following the Join name (before it was 1.4, now it is 1.2). I'm not sure if that makes a difference.
DevBiker, our original example worked in linqpad, which leads me to believe the issue lies somewhere in the input/output adapter type setup. Obviously, this hasn't been confirmed. However, we are using the Reflection namespace's MakeGeneric methods to instantiate the items we need.
Our next step is to temporarily remove the generic typing methods and have all types hard-coded. Hopefully, that will lead us to a solution. I'll post back here once I have more information.
Thanks again!
- Marqué comme réponse Roman SchindlauerMicrosoft Employee jeudi 9 août 2012 05:02


