参数必须是DomainService公开的实体类型?

发布于 2024-12-10 10:51:19 字数 948 浏览 0 评论 0原文

尝试在 SL 应用程序中实现域服务并收到以下错误:

域方法“CreateSharePointFolder”的参数“spFolderCreate”必须是由 DomainService 公开的实体类型。

 [EnableClientAccess()]
public class FileUploadService : DomainService
{
    public void CreateSharePointFolder(SharePointFolderCreate spFolderCreate)
    {
        SharePointFolder spf = new SharePointFolder();
            spf.CreateFolder_ClientOM(spFolderCreate.listName, spFolderCreate.fileName);
    }

 [OperationContract]
    void CreateSharePointFolder(SharePointFolderCreate spFolderCreate);

[DataContract]
public class SharePointFolderCreate
{
    private string m_listName;
    private string m_fileName;

    [DataMember]
    public string listName
    {
        get { return m_listName; }
        set { m_listName = value; }
    }

    [DataMember]
    public string fileName
    {
        get { return m_fileName; }
        set { m_fileName = value; }
    }
}

那么我是否缺少一些简单的东西来使这一切正常工作?

Trying to implement a domain service in a SL app and getting the following error:

Parameter 'spFolderCreate' of domain method 'CreateSharePointFolder' must be an entity type exposed by the DomainService.

 [EnableClientAccess()]
public class FileUploadService : DomainService
{
    public void CreateSharePointFolder(SharePointFolderCreate spFolderCreate)
    {
        SharePointFolder spf = new SharePointFolder();
            spf.CreateFolder_ClientOM(spFolderCreate.listName, spFolderCreate.fileName);
    }

 [OperationContract]
    void CreateSharePointFolder(SharePointFolderCreate spFolderCreate);

[DataContract]
public class SharePointFolderCreate
{
    private string m_listName;
    private string m_fileName;

    [DataMember]
    public string listName
    {
        get { return m_listName; }
        set { m_listName = value; }
    }

    [DataMember]
    public string fileName
    {
        get { return m_fileName; }
        set { m_fileName = value; }
    }
}

So am I missing something simple here to make this all work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橙幽之幻 2024-12-17 10:51:19

框架可能正在推断预期的操作,因为函数名称 (CreateSharePointFolder) 前面有“Create”一词。此行为的详细信息可以在此处找到,

尽管这对于 DomainServices 来说没什么问题和EntityFramework,根据该文章中的信息,可以推断以“Delete”开头的方法将执行实体的删除,因此必须接受实体作为参数。对于“Create”或“Ins​​ert”前缀方法也是如此。只有“Get”或“Select”方法可以采用非实体参数,从而可以将数字 id(例如)传递给“Get”方法。

尝试暂时将方法名称更改为“BlahSharePointFolder”,看看是否是这种推理约定导致了您的问题。

此外,由于没有为 SharePointFolderCreate DC 定义元数据,因此您可能需要使用 [MetadataType] 属性来装饰该类(除了 [DataContract] 属性之外)。如果您使用 DomainServiceClass 向导并指向 EF 模型,您将了解如何实现这一点。底部有一个用于生成元数据的复选框。在您的解决方案.Web 项目中的某个位置,您应该可以找到domainservice.metadata.cs 文件。在此文件中,您将找到如何使用 [MetadataType] 属性的示例。

为了让 RIA WCF 服务能够正确地使用您自己的方法,您需要确保参数列表中存在的所有实体至少有一个在其元数据类中定义了 [Key] 属性的成员,并且该实体返回到您的 DomainService 在“Get”方法中。

HTH

It may be that the framework is inferring the intended operation because you have the word "Create" prefixing the function name (CreateSharePointFolder). Details of this behaviour can be found here

Although that is all fine for DomainServices and EntityFramework, following the information in that article, it can be inferred that methods beginning "Delete" will be performing a delete of an entity, so must accept an entity as a parameter. The same is true for "Create" or "Insert" prefixed methods. Only "Get" or "Select" methods can take non-entity parameters, making it possible to pass a numeric id (for example) to a "Get" method.

Try changing your method name temporarily to "BlahSharePointFolder" to see if it is this convention of inferrance that's causing your problem.

Also, as there is no metadata defined for your SharePointFolderCreate DC, you might need to decorate the class (in addition to the [DataContract] attribute) with the [MetadataType] attribute. You will see how to implement this if you used the DomainServiceClass wizard and point to an EF model. There is a checkbox at the bottom for generating metadata. Somewhere in your solution.Web project you should find a domainservice.metadata.cs file. In this file, you will find examples of how to use the [MetadataType] attribute.

For the RIA WCF service to work correctly with your own methods, you need to ensure that all entities existing on the parameter list have at least one member with a [Key] attribute defined in their metadata class, and that the entity is returned somewhere on your DomainService in a "Get" method.

HTH

Lee

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文