ASP.NET

Moderators: None (Apply to moderate this forum)
Number of threads: 1735
Number of posts: 3309

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Create XML file using LINQ to Entities VB.NET Posted by lionb on 27 May 2010 at 6:24 AM
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.
 Dim xmlContext = <CountiesMunicipalities>
                             <County><%= From cm In mData.COUNTIES _
                                         Where cm.STATE_ID = 39 _
                                         Select <Name><%= cm.NAME %></Name> %></County>
                         </CountiesMunicipalities>

Tried to run it with LINQ to Entities and got Error:
Only parameterless constructors and initializers are supported in LINQ to Entities.
I understand that LINQ to Entities takes a different approach than LINQ to SQL in some areas.
I tried to use XML options:
Dim xmlContext = From cm In mData.COUNTIES _
                                         Where cm.STATE_ID = 39 _
                                        Select New XElement("CountiesMunicipalities",
                                                            New XAttribute("County", cm.NAME))

and got the same result
Does somebody know how to use LINQ to Entities to create XML File?
Report
Re: Create XML file using LINQ to Entities VB.NET Posted by lionb on 27 May 2010 at 6:31 AM
Never mind people. I figured out how to fix it. Need to use ToList(). Here it is code - bold red changes
Dim xmlContext = <CountiesMunicipalities>
                             <County><%= From cm In mData.COUNTIES.ToList _
                                         Where cm.STATE_ID = 39 _
                                         Select <Name><%= cm.NAME %></Name> %></County>
                         </CountiesMunicipalities>



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.