This is a migrated thread and some comments may be shown as answers.

String Concatenation using Lambda Expression

3 Answers 512 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Frank Schürer
Top achievements
Rank 1
Frank Schürer asked on 28 Oct 2010, 11:14 AM
Hi,

i try to get this code snippet working

AddInfos = (From Infos In m_gdScope.Extent(Of HaushaltePlz)() _
                                Select New With {Infos.Plz, .Value = Infos.Ort & "|" & Infos.HhBrutto & "|" & Infos.HhNetto}).OrderBy(Function(p) p.Plz).ToDictionary(Function(dic) dic.Plz, Function(dic) dic.Value)
AddInfos = (From Infos In m_gdScope.Extent(Of HouseHoldsZip)() _
Select New With {Infos.Zip, .Value = Infos.City & "|" & Infos.HH1 & "|" & Infos.HH2}).OrderBy(Function(p) p.Zip).ToDictionary(Function(dic) dic.Zip, Function(dic) dic.Value)

but i am getting the following error message:

System.InvalidOperationException was not handled.
  Message="An exception occured during the execution of '\r\nExtent<GeoDataClasses.HouseholdsZip>.Select(Infos => new VB$AnonymousType_21`2(Zip = Infos.Zip, Value = Concat(new [] {Infos.City, \"|\", (Infos.HH1 ?? null), \"|\", (Infos.HH2 ?? null)})))'. See InnerException for more details.\r\n"
  Source="Telerik.OpenAccess.35.Extensions"
  StackTrace:
       at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues)
       at Telerik.OpenAccess.Query.ExpressionExecution.PerformDatabaseQuery[T](Piece`1 piece, Object[] grpVals)
       at Telerik.OpenAccess.Query.Piece`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
       at Telerik.OpenAccess.Query.TypedEnumerableWrapper`1.GetEnumerator()
       at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
       at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
       at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
       at MediaCenter.MedienSelektionKonzepte.btnAddConcept_Click(Object sender, EventArgs e) in C:\Projects\MediaCenter\MediaCenter\Forms\MediaSelectionConcepts.vb:Row 399.
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at Telerik.WinControls.RadControl.OnClick(EventArgs e)
       at Telerik.WinControls.UI.RadButton.ButtonElement_Click(Object sender, EventArgs e)
       at Telerik.WinControls.RadItem.OnClick(EventArgs e)
       at Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e)
       at Telerik.WinControls.RadItem.DoClick(EventArgs e)
       at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e)
       at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)
       at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at Telerik.WinControls.RadControl.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at MediaCenter.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Row 81.
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at System.Activator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.InvalidCastException
       Message="The object of type \"System.Linq.Expressions.NewArrayExpression\" cannot be converted to Type \"OpenAccessRuntime.DataObjects.query.Node\
       Source="Telerik.OpenAccess.35.Extensions"
       StackTrace:
            at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type type, Int32 elementAt, Object[] groupResolutionParamValues)
            at
Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues)
       InnerException:

How can i put the three fields City, HH1 and HH2 into one value field for the dictionary?

Thanks for every comment!

3 Answers, 1 is accepted

Sort by
0
Petko_I
Telerik team
answered on 03 Nov 2010, 09:20 AM
Hello Frank Schürer,

We are writing to let you know that we have been able to reproduce a similar behavior and started investigating the cause for it. Judging by the translation of the query into an expression, the HH1 and HH2 are of nullable types for which the conversion and concatenation fails. Can you tell us exactly what types these properties have? Would you mind also giving us the inner exception (if any)? Can you also replace the "&" sign with a "+" and tell us if there is any difference?

We are looking forward to resolving this issue.

Sincerely yours,
Petko_I
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Frank Schürer
Top achievements
Rank 1
answered on 03 Nov 2010, 10:22 AM
Hello,

the inner exception is:

{"Object of type \"System.Linq.Expressions.NewArrayExpression\" cannot be converted to type \"OpenAccessRuntime.DataObjects.query.Node\"."}

StrackTrace:

"   at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type type, Int32 elementAt, Object[] groupResolutionParamValues)\r\n   at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues)"

It's just a cast problem because of different field types, but i guess you already noticed that ;).

More information on the field types is listed below:

<Telerik.OpenAccess.FieldAlias("_hh1")> _
Public Property Hh1() As Nullable(Of Integer)
    Get
        Return _hh1
    End Get
    Set( ByVal Value As Nullable(Of Integer) )
        Me._hh1 = Value
    End Set
End Property
 
<Telerik.OpenAccess.FieldAlias("_hh2")> _
Public Property Hh2() As Nullable(Of Integer)
    Get
        Return _hh2
    End Get
    Set( ByVal Value As Nullable(Of Integer) )
        Me._hh2 = Value
    End Set
End Property
 
<Telerik.OpenAccess.FieldAlias("_city")> _
Public Property City() As String
    Get
        Return _city
    End Get
    Set( ByVal Value As String )
        Me._city = Value
    End Set
End Property

Hope these information help.
0
Petko_I
Telerik team
answered on 09 Nov 2010, 12:40 PM
Hello Frank Schürer,

Thank you for your patience and your input. We have investigated this issue and are currently addressing it. We will try to include the fix for the Q3 release. As a workaround I would suggest making a helper class which contains properties for the fields you want to concatenate. Then instead of a concatenated string for the value of the dictionary you will have a composite class. I hope this will serve as a good start for now.

We apologize for the inconvenience caused once again. Do not hesitate to contact us to ask anything that comes to your mind.

Regards,
Petko_I
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
LINQ (LINQ specific questions)
Asked by
Frank Schürer
Top achievements
Rank 1
Answers by
Petko_I
Telerik team
Frank Schürer
Top achievements
Rank 1
Share this question
or