Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 545805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:48:02+00:00 2026-05-13T10:48:02+00:00

Is there a simpler way to output a Linq to SQL table to XML

  • 0

Is there a simpler way to output a Linq to SQL table to XML (eventually to a web page?) Unfortunately, I am not using MVC, but I could put a reference to it in my aspx C# page.

I have this:

var myView = (from x in db.myTable 
              where x.Name.Contains("Bob") 
              select new person {Name = x.Name, Job = x.Job).Take(100);

and want to output something similar to this (doesn’t have to be exact for now):

<?xml version="1.0" encoding="utf-8"?> 
<myView xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <person><Name>Bob Smith</Name><Job>Machinist</Job></person>
    <person><Name>Bob Smithers</Name><Job>Cartoonist</Job></person>
    <person><Name>Rebob Wilson</Name><Job>Mason</Job></person>
</myView> 

I tried doing this:

TextWriter myTW = new StreamWriter( Response.OutputStream, Encoding.UTF8);
XmlTextWriter xmlTW = new XmlTextWriter(myTW);
XmlSerializer myS = new XmlSerializer( typeof( person));
myS.Serialize( xmlTW, myView);

But I get a “Cannot serialize iQueryable”. However, I tried ToArray, ToList, AsEnumerable, etc. and simply get “An error occured” with myS.Serialize().

Any thoughts? Hopefully there is a way like return XML(myView);

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:48:02+00:00Added an answer on May 13, 2026 at 10:48 am

    Try this:

    var result = myView.ToArray();
    var serializer = new XmlSerializer(result.GetType());
    serializer.Serialize(Response.OutputStream, result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've discovered a very nasty gotcha with Linq-to-sql, and i'm not sure what the
Is there a simple way to scale the pdf created by cfdocument or cfpdf
I need to write model data ( CharField s only) to an XML file
So I've been using Handbrake command line to encode my video collection to store
Is there an OS or user-account level modification for windows 7 that I can
Hopefully this should be an easy answer for someone out there (and possibly a
I have a client/server question that i am trying to figure out the best
I have a working solution right now, but it seems really ugly for something
I am working a C firmware program for an embedded device. I want to
I understand that repr() 's purpose is to return a string, that can be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.