Using datacontractserializer can i serialize anoyonous types

Posted on 2009-04-26
Last Modified: 2013-12-17
Using a LINQ statment i join on two tables and create an anonymous type e.g.

            var query = from c in dc.supplier
                        join x in dc.address on c.PrimaryKey equals x.Fk_Supplier
                        select new { c, x };

Is it possible to use the datacontractserializer and serialize the resultant query to send over the wire?

Question by:erik_bradshaw
    1 Comment
    LVL 23

    Accepted Solution

    Not directly - you'll get an InvalidDataContractException.

    You should be able to use Reflection to create a class dynamically, apply the DataContractAttribute to the class, apply the DataMemberAttribute to the members you want to serialize, build objects of that class FROM your query, and serialize THAT - I'm not sure you want to go through all that effort, though.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now