关于将代码从RIA Services July Preview更新到RIA Services 1.0的快速问题

时间:2010-08-23 07:57:10

标签: .net silverlight wcf-ria-services

我对Silverlight的Web服务/数据库抽象层方面没有太多经验,并且我在移植工作方面遇到了一些问题。项目中有一个不再涉及的核心C#开发人员,我正在使用他编写的代码。

我正在使用RIA Services 1.0将带有RIA Services预览版的SL3项目的代码更新到SL4。我正在引用RIA_Services_Breaking_Changes.doc文件,以便从此URL进行代码转换工作: http://code.msdn.microsoft.com/RiaServices/Release/ProjectReleases.aspx?ReleaseId=3570

我的挂断是我认为可能是自动生成的文件,以及涉及RIA Services EntityCollection / EntityState内容的错误。

HerculesModel.metadata.cs(开始转换之前)

namespace Everest.Domain.Hercules
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using System.Web.Ria;
    using System.Web.Ria.Data;
    using System.Web.DomainServices;
    using System.Data;
    using System.Data.Objects.DataClasses;

    // The MetadataTypeAttribute identifies AuthenticationTypesMetadata as the class
    // that carries additional metadata for the AuthenticationTypes class.
    [MetadataTypeAttribute(typeof(AuthenticationTypes.AuthenticationTypesMetadata))]
    public partial class AuthenticationTypes
    {
        // This class allows you to attach custom attributes to properties
        // of the AuthenticationTypes class.
        //
        // For example, the following marks the Xyz property as a
        // required field and specifies the format for valid values:
        //  [Required]
        //  [RegularExpression("[A-Z][A-Za-z0-9]*")]
        //  [StringLength(32)]
        //  public string Xyz;
        internal sealed class AuthenticationTypesMetadata
        {
            // Metadata classes are not meant to be instantiated.
            private AuthenticationTypesMetadata()
            {
            }
            public EntityState EntityState;
            public EntityCollection<LoginAccounts> LoginAccounts;
            public int TypeId;
            public string TypeName;
        }
    }
    ...
}

我更新了对上面重大更改文档中列出的新命名空间的使用引用,并测试了构建。 Visual Studio随后在文档中列出了以下错误274次:

Error 53 'EntityCollection' is an ambiguous reference between 'System.ServiceModel.DomainServices.Client.EntityCollection<Everest.Domain.Hercules.BookmarkedProfiles>' and 'System.Data.Objects.DataClasses.EntityCollection<Everest.Domain.Hercules.BookmarkedProfiles>'   C:\...\Everest.Domain.Hercules\HerculesModel.metadata.cs    872 11  Everest.Domain.Hercules
Error 189 'EntityState' is an ambiguous reference between 'System.ServiceModel.DomainServices.Client.EntityState' and 'System.Data.EntityState' C:\...\Everest.Domain.Hercules\HerculesModel.metadata.cs    3501    11  Everest.Domain.Hercules

所以我更新了代码,添加了限定符以消除歧义:

namespace Everest.Domain.Hercules
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using System.ServiceModel.DomainServices.Server;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Client;
    using System.ServiceModel.DomainServices;
    using System.Data;
    using System.Data.Objects.DataClasses;  
    [MetadataTypeAttribute(typeof(AuthenticationTypes.AuthenticationTypesMetadata))]
    public partial class AuthenticationTypes
    {
        internal sealed class AuthenticationTypesMetadata
        {
            private AuthenticationTypesMetadata()
            {
            }
            public System.ServiceModel.DomainServices.Client.EntityState EntityState;
            public System.ServiceModel.DomainServices.Client.EntityCollection<LoginAccounts> LoginAccounts;
            public int TypeId;
            public string TypeName;
        }
    }
    ...
}

尝试构建代码后,我收到以下一般错误160次,而且我完全停留在这些TEntity错误上:

Error 28 The type 'Everest.Domain.Hercules.Authentication.LoginAccounts' cannot be used as type parameter 'TEntity' in the generic type or method 'System.ServiceModel.DomainServices.Client.EntityCollection<TEntity>'. There is no implicit reference conversion from 'Everest.Domain.Hercules.Authentication.LoginAccounts' to 'System.ServiceModel.DomainServices.Client.Entity'.   C:\...\Everest.Domain.Hercules\Authentication\AuthenticationModel.metadata.cs   358 85  Everest.Domain.Hercules

我为Visual Studio 2010安装了Resharper,它声明文档使用的唯一using指令是System和System.ComponentModel.DataAnnotations。据我所知* .metadata.cs文件是自动生成的,但如何重新生成元数据文件并支持这个新版本的RIA服务?该项目使用开源MVVM框架。

万分感谢您提供给我的任何帮助!!!

1 个答案:

答案 0 :(得分:0)

您不应该在您的using语句中包含S.SM.DS.Client。客户端程序集应仅链接到Silverlight项目。

凯尔