Locations of visitors to this page


Linq 2 entities and XML

Onteora Software

Ken Tucker's Blog

About the author

Author Name is someone.
E-mail me Send mail

Recent posts

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Linq 2 entities and XML

When using Linq 2 Sql with Linq to Xml in VB you could write code like this to generate xml

 

Dim db As New NorthwindDataContext
 

Dim xmlLinq2Sql = <root><%= From emp In db.Employees _
                            Select <Employee id=<%= emp.EmployeeID %>><%= emp.FirstName & " " & emp.LastName %>
                                   </Employee> %>
                  </root>

 

Which will generate xml  like this

<root>
  <Employee id="1">Nancy Davolio</Employee>
  <Employee id="2">Andrew Fuller</Employee>
  <Employee id="3">Janet Leverling</Employee>
  <Employee id="4">Margaret Peacock</Employee>
  <Employee id="5">Steven Buchanan</Employee>
  <Employee id="6">Michael Suyama</Employee>
  <Employee id="7">Robert King</Employee>
  <Employee id="8">Laura Callahan</Employee>
  <Employee id="9">Anne Dodsworth</Employee>
</root>

 

The entity framework requires a more explicit format for the query

 

Dim entDB As New NorthwindModel.NorthwindEntities

Dim xmlLinq2Entities = <root><%= From ent In entDB.Employees.AsEnumerable _
                                 Select <Employee id=<%= ent.EmployeeID %>><%= ent.FirstName & " " & ent.LastName %>
                                        </Employee> %>
                       </root>

 

 

Hope this helps

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Ken Tucker on Monday, June 30, 2008 12:58 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

Thursday, September 04, 2008 8:42 PM