简体   繁体   English

部分代码未与RIA服务生成的(重新)生成的代码一起编译

[英]Partial code not compiling with (re)generated code from RIA service

Here is an issue that has bogged my mind for a while now. 这是一个困扰了我一段时间的问题。 I have searched the breadths of the internet to no avail, and have at last come to ask SO for assistance. 我搜索了互联网的广度无济于事,最后来向SO寻求帮助。

I have a full .NET stack assembly project in VS2015 in which I have implemented RIA domain services. 我在VS2015中有一个完整的.NET堆栈组装项目,在其中已经实现了RIA域服务。 The RIA service is exposed to a Silverlight 5.0 client project over WCF (HTTP), where it is referenced as service reference. RIA服务通过WCF(HTTP)公开给Silverlight 5.0客户端项目,在此将其称为服务参考。 This triggers an automated code generation for the RIA proxy classes at the Silverlight project, which happens at build-time. 这将触发Silverlight项目中RIA代理类的自动代码生成,该代码生成在构建时发生。 This Silverlight project is the only location where I have this WCF RIA service referenced. 这个Silverlight项目是我引用此WCF RIA服务的唯一位置。 The Silverlight project itself is referenced by two separate Silverlight applications. Silverlight项目本身由两个单独的Silverlight应用程序引用。

This Silverlight project also contains partial classes that extend the RIA proxy classes. 该Silverlight项目还包含扩展RIA代理类的部分类。 When building one of the Silverlight solutions, it often (but not always) throws errors for the partial classes that extend the RIA proxy classes. 在构建其中一个Silverlight解决方案时,它经常(但不总是)引发扩展RIA代理类的部分类错误。 The generated code file with the proxy classes has disappeared (I assume because VS deletes it before recreating it), and the references in the partial class are broken. 生成的带有代理类的代码文件已经消失(我想是因为VS在重新创建它之前将其删除),并且部分类中的引用已损坏。

As an example, this is a RIA generated proxy class (only showing the ExaminationResult property, as it would otherwise become too lengthy): 例如,这是RIA生成的代理类(仅显示ExaminationResult属性,否则它会变得太长):

    public sealed partial class VCtp_DetailedResults : Entity
    {
        // ... more properties here

        /// <summary>
        /// Gets or sets the 'ExaminationResult' value.
        /// </summary>
        [DataMember()]
        [Editable(false, AllowInitialValue=true)]
        [Key()]
        [Required()]
        [RoundtripOriginal()]
        [StringLength(11)]
        public string ExaminationResult
        {
            get
            {
                return this._examinationResult;
            }
            set
            {
                if ((this._examinationResult != value))
                {
                    this.OnExaminationResultChanging(value);
                    this.ValidateProperty("ExaminationResult", value);
                    this._examinationResult = value;
                    this.RaisePropertyChanged("ExaminationResult");
                    this.OnExaminationResultChanged();
                }
            }
        }
    }

And this is the partial extension: 这是部分扩展:

namespace Apss.Data.Reports.Models
{
    public partial class VCtp_DetailedResults : IRow, IRowCtp, IRowCustomer
    {
        public bool IsVisible { get; set; }
        public bool IsSelected { get; set; }

        public string ExaminationResultLocalized
        {
            get { return LocalisationHelper.GetString(ExaminationResult); }
        }
    }
}

The build error is: 生成错误是:

在此处输入图片说明

As you can see in this screenshot: 如您在此屏幕截图中所见: 在此处输入图片说明

My assumption is that VS goes through at least two iterations of compilation during a build, one where the local code is compiled, and another where the RIA proxy code is generated and compiled. 我的假设是,VS在构建过程中至少经历了两次编译迭代,其中一个编译本地代码,而另一个生成和编译RIA代理代码。

My question: how do I ensure that the build does not break with these partial proxy classes? 我的问题:如何确保构建不会因这些部分代理类而中断?

One approach is to take the generated code .g.cs and check it into source, and then turn off RIA Service. 一种方法是采用生成的代码.g.cs并将其检入源代码,然后关闭RIA服务。

You can turn on RIA Service when your services change, much like how one would regenerate proxies if services changed. 您可以在服务更改时打开RIA服务,就像在服务更改时如何重新生成代理一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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