• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1015
  • Last Modified:

Using datacontractserializer can i serialize anoyonous types

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?

0
erik_bradshaw
Asked:
erik_bradshaw
1 Solution
 
Jens FiedererCommented:
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.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now