Create XML file using LINQ to Entities VB.NET

I am tring to create XML file using ASP-VB.NET (Visual Studio 2008/2010)
When I use following code with LINQ to SQL it works perfectly.
[code] Dim xmlContext =
<%= From cm In mData.COUNTIES _
Where cm.STATE_ID = 39 _
Select <Name><%= cm.NAME %> %>
[/code]
Tried to run it with LINQ to Entities and got Error:
[color=Blue]Only parameterless constructors and initializers are supported in LINQ to Entities.[/color]
I understand that LINQ to Entities takes a different approach than LINQ to SQL in some areas.
I tried to use XML options:
[code]Dim xmlContext = From cm In mData.COUNTIES _
Where cm.STATE_ID = 39 _
Select New XElement("CountiesMunicipalities",
New XAttribute("County", cm.NAME))[/code]
and got the same result
Does somebody know how to use LINQ to Entities to create XML File?

Comments

  • Never mind people. I figured out how to fix it. Need to use ToList(). Here it is code - bold red changes
    [code]Dim xmlContext =
    <%= From cm In [color=Red][b]mData.COUNTIES.ToList [/b][/color]_
    Where cm.STATE_ID = 39 _
    Select <Name><%= cm.NAME %> %>
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion