Currently am working on a project that requires me to create some XML for use with a graphing plugin. I’m using XML literals and LINQ to SQL as follows
Dim x As XElement = _
<chart caption='Aantal aanvragen' xAxisName='Dag' yAxisName='Aantal'>
<%= From d In dailies Select _
<set label=<%= d.Datum %> value=<%= d.Aantal %>>
</set> %>
</chart>
Dailies is just a more complex Linq query, Datum is of type Date? and Aantal of type Int.
Now my problem is how to format the date properly. I thought that would be something like:
<%= CDate(d.Datum).ToString("d MMM yyyy") %>
Unfortunately that gives me:
System.NotSupportedException: Method ‘System.String ToString(System.String)’ has no supported translation to SQL.
Does anyone have a solution to this? Thanks in advance.
If you want to construct the XML contents you could make sure the data is pulled from SQL server by adding
AsEnumerable()e.g.that way you can avoid the problem with the attempt to translate your method call ToString() into SQL.
You will need to decide however, if that table column indeed contains null values respectively if you indeed get
d.Datumas Nothing for some items what you want to do in that case, either make sure you exclude those items with e.g.or use the
Ifoperator to output some default. But that’s more a VB problem than an LINQ to XML problem and VB is not my strength so maybe you already have that sorted yourself.