Note that there are some explanatory texts on larger screens.

plurals
  1. POGeneric return types from abstract/virtual methods
    primarykey
    data
    text
    <p>I have a relationship between two base classes:</p> <pre><code>public abstract class RecruiterBase&lt;T&gt; { // Properties declare here // Constructors declared here public abstract IQueryable&lt;T&gt; GetCandidates(); } public abstract class CandidateBase&lt;T&gt; { // Properties declare here // Constructors declared here } </code></pre> <p>And their concrete implementations as such:</p> <pre><code>public class CandidateA : CandidateBase&lt;CandidateA&gt; { // Constructors declared here } public class RecruiterA : RecruiterBase&lt;RecruiterA&gt; { // Constructors declared here // ----HERE IS WHERE I AM BREAKING DOWN---- public override IQueryable&lt;CandidateA&gt; GetCandidates() { return from c in db.Candidates where c.RecruiterId == this.RecruiterId select new CandidateA { CandidateId = c.CandidateId, CandidateName = c.CandidateName, RecruiterId = c.RecruiterId }; } } </code></pre> <p>Per MSDN documentation <a href="http://msdn.microsoft.com/en-us/library/ms379564%28VS.80%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms379564%28VS.80%29.aspx</a> (about half way down) and a similiar (but not identical) questoin on SO <a href="https://stackoverflow.com/questions/675857/c-specifying-the-return-type-of-an-abstract-method-from-a-base-class-according">Specifying the return type of an abstract method from a Base Class according to a Sub Class</a></p> <p>I can make use of my concreate implementation for the return type of my overridden method GetCandidates but that is not what I want, I want to make use of the concrete implementation of a different abstract class. This is a parent/child database relationship. Is what I am trying to achieve possible? I currently get a compile time error that my GetCandidates return type does not match.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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