Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Create XML file using LINQ to Entities VB.NET

lionblionb Posts: 1,688Member ✭✭
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

  • lionblionb Posts: 1,688Member ✭✭
    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.