开发者

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 开发者_JAVA技巧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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜