Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework & RIA Services - cant access protected property in shared class on client
    primarykey
    data
    text
    <p>I have an abstract class that's autogenerated by a code template. We then have several classes that derive from this class. There is a particular property on that class that for one of the derived implementations I would like to override the getter and setter. Unfortunately I can find no way of overriding the property as it is not declared virtual.</p> <p>So as another approach, I decided to make the property protected, and then in the partial class (<code>.shared.cs</code>) create a public virtual property that effectively wraps the protected one. Then I can override this in the one specific implementation.</p> <p>So on the server side this looks fine, but once I build it, it turns out that the partial shared file that ria generates for me on the client seems to have no visibility of the protected property.</p> <p><code>ClassA.cs</code>:</p> <pre><code>//------------------------------------------------------------------------------ // &lt;auto-generated&gt; // This code was generated from a template. // // Manual changes to this file may cause unexpected behaviour in your application. // Manual changes to this file will be overwritten if the code is regenerated. // &lt;/auto-generated&gt; //------------------------------------------------------------------------------ namespace ABC.Web.Models.DomainModel { using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; [RoundtripOriginal] public abstract partial class ClassA { public int Id { get; set; } public string Title { get; set; } protected string ApplicationNumber { get; set; } } } </code></pre> <p><code>ClassA.shared.cs</code></p> <pre><code>namespace ABC.Web.Models.DomainModel { using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; public abstract partial class ClassA { [IgnoreDataMember] public virtual string ApplicationNumberAccessor { get { return this.ApplicationNumber; } set { this.ApplicationNumber = value; } } } } </code></pre> <p>This effectively gives the error <code>'ABC.Web.Models.DomainModel.ClassA' does not contain a definition for 'ApplicationNumber' and no extension method 'ApplicationNumber' accepting a first argument of type 'ABC.Web.Models.DomainModel.ClassA' could be found (are you missing a using directive or an assembly reference?)</code></p> <p>When double clicking the error it takes me to the client version of the file, where for some reason it can not see that protected property.</p> <p>Any idea why? or alternatively is there a way (using Database first) to mark a field so it generates as virtual?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload