gpt4 book ai didi

c# - 如何将自定义类型与 WCF 数据服务和 EF 一起使用

转载 作者:太空宇宙 更新时间:2023-11-03 14:14:14 24 4
gpt4 key购买 nike

我已经使用我的 EF 模型的基类创建了一个 WCF 数据服务。

我想返回一个自定义类型(一个不在我的 EF 模型中的类型),但我收到错误:

The server encountered an error processing the request. Please see the service help 
page for constructing valid requests to the service.

我的自定义类如下所示:

public class MyCustomClass
{
public string CustomProp { get; set; }
public List<int> Ids { get; set; }
}

我怎样才能让它工作?

最佳答案

您需要将返回对象设置为数据协定:

[DataContract]
public class MyCustomClass
{
[DataMember]
public string CustomProp { get; set; }

[DataMember]
public List<int> Ids { get; set; }
}

另请参阅:How to accept JSON in a WCF DataService?

链接是如何设置接收服务,返回您刚刚更改方法返回类型的值。

关于c# - 如何将自定义类型与 WCF 数据服务和 EF 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6962446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com