简体   繁体   中英

How to return a LINQ to SQL Table entity from a WCF Service?

The following method in my WCF implementation:

public Campaign GetCampaignByDisplayName( String displayName )

where Campaign is a table in my SQL Server database, my client app throws an exception when the above method returns. From other related posts, I've read that the problem probably has to do with Campaign not being serializable. Going into the generated database designer source file, and duly ignoring the admonishment "Changes to this file may cause incorrect behavior..." I add the [Serializable] attribute to the Campaign class, resulting in a non-compilable Proxy file once that's regenerated.

Clearly I'm missing a critical concept here. What do I need to do to be able to pass a LINQ to SQL record in this manner?

Mark the Campaign class with DataContractAtribute .
Mark any members which you wish to be passed via the web service with the DataMemberAttribute .

There is a decent primer on MSDN - http://msdn.microsoft.com/en-us/library/ms733127.aspx

If you are using sqlmetal use /serialization:Unidirectional

http://msdn.microsoft.com/en-us/library/bb386987.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM