Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo generic types in a extension method
    text
    copied!<p><strong>Right now my code is code looks something like this: (Simplified!)</strong></p> <pre><code>public static IQueryable&lt;T&gt; ListedProducts&lt;T,V&gt;(this IQueryable&lt;T&gt; collection) where T : ProductCollection&lt;V&gt; where V: Product { return collection.Where(x =&gt; x.Listed == true); } </code></pre> <p>And to use it i have to define both Types like this:</p> <pre><code>SomeCollection.ListedProducts&lt;BikeCollection,BikeProduct&gt;() </code></pre> <hr> <p><strong>This is how i would like it to be:</strong></p> <p>I want to be able to write something lkie this:</p> <pre><code>public static IQueryable&lt;T&gt; ListedProducts&lt;T&lt;V&gt;&gt;(this IQueryable&lt;T&lt;V&gt;&gt; collection) where T : ProductCollection&lt;V&gt; { return collection.Where(x =&gt; x.Listed == true); } </code></pre> <p>Where i only needed to write:</p> <pre><code>SomeCollection.ListedProducts() </code></pre> <p>I think it's possible since "SomeCollection" contains both types for the generic ListedProducts method.</p> <hr> <p>Hope my question is clear enough and there is a solution :)</p> <hr> <p><strong>UPDATE</strong></p> <p>There seem to be many fustrations on how my code is set up, so here are some of the classes (simplified)</p> <p><strong>ProductCollection</strong></p> <pre><code>public class ProductCollection&lt;T&gt; where T : Product { public int Id { get; set; } public string CollectionName { get; set; } public virtual ICollection&lt;T&gt; Products { get; set; } public bool Listed { get; set; } } </code></pre> <p><strong>ProductCollection</strong></p> <pre><code>public class BikeCollection : ProductCollection&lt;BikeProduct&gt; { //Bike specific properties } </code></pre>
 

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