Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7716739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:42:29+00:00 2026-06-01T02:42:29+00:00

I have a class /interface hierarchy. On the interface side I have IQuery ISelect

  • 0

I have a class /interface hierarchy. On the interface side I have

IQuery
  ISelect      (inherits IQuery)
  IUpdate      (inherits IQuery)
  etc

On the class side I have

QueryBase       (implements IQuery)
  SelectQuery   (implements ISelect)
  UpdateQuery   (implements IUpdate)
  etc

Obviously, for example, both Update and Select classes share a WHERE clause but only a Select has GROUP BY functionality so ideally if an Update Query is being creating, the fluent interface will not give access to GROUP BY functionality but would do if a SelectQuery was being created.

eg in fluent interface terms

  var/Dim select = New SelectQuery()        <- returns ISelect explicit
                          .AddColumn(....)  <- returns ISelect explicit
                          .AddWhere(....)   <- returns ISelect inferred
                          .AddGroupBy(....) <- returns ISelect explicit

  var/Dim update = New UpdateQuery()        <- returns IUpdate explicit
                          .AddSet(....)     <- returns IUpdate explicit
                          .AddWhere(....)   <- returns IUpdate inferred

I am unsure how to implement the AddWhere function.

Previously I had declared the AddWhere function in the IQuery interface as

Function AddWhere(ByVal condition As ICriterion) As IQuery

IQuery AddWhere(ICriterion condition)

but because it was returning an IQuery, I was losing the benefits of the type inference and so as soon as the fluent interface had cast to the IQuery, if it was a Select query being created, I would no longer have access to, eg, the AddGroupBy method.

So I have tried to implement it as an Extension Method with generics

<Extension>
Public Function AddWhere(Of T As IQuery)(Byval this as T, Byval condition as Condition) as T
    this.SetWhere(condition)
    Return Me
End Function

public T AddWhere<T>(T @this, Condition condition) where T : IQuery
{
    @this.SetWhere(condition);
    return this;
}

with a Friend (internal) method, SetWhere, on QueryBase to permit me to update the WHERE clause. However because the generic is constrained to IQuery, it won’t find the SetWhere. However, if I constrain as QueryBase, then, obviously, the compiler throws wobblies saying that the ISelect can’t find an AddWhere method.

I’m thinking that I haven’t quite got the inheritence chain or interface implementations quite right for what I’m trying to achieve.

(I hope that is clear!!)

I’d be grateful if someone could suggest either where I am going wrong in terms of the extension method implementation, or how I should better structure my class/interface hierarchy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:42:31+00:00Added an answer on June 1, 2026 at 2:42 am
    Public Interface IQuery
        Function AddWhere() As IQuery
    End Interface
    
    Public Interface IUpdate : Inherits IQuery
        Overloads Function AddWhere() As IUpdate
    End Interface
    
    Public Interface ISelect : Inherits IQuery
        Overloads Function AddWhere() As ISelect
        Function AddGroupBy() As ISelect
    End Interface
    
    Public Class QueryBase : Implements IQuery
        Public Function AddWhere() As IQuery Implements IQuery.AddWhere
            ''...
            Return Me
        End Function
    End Class
    
    Public Class UpdateQuery : Inherits QueryBase : Implements IUpdate
        Public Shadows Function AddWhere() As IUpdate Implements IUpdate.AddWhere
            MyBase.AddWhere()
            Return Me
        End Function
    End Class
    
    Public Class SelectQuery : Inherits QueryBase : Implements ISelect
        Public Shadows Function AddWhere() As ISelect Implements ISelect.AddWhere
            MyBase.AddWhere()
            Return Me
        End Function
        Public Function AddGroupBy() As ISelect Implements ISelect.AddGroupBy
            ''...
            Return Me
        End Function
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class Animal and an interface it inherits from IAnimal. @MappedSuperclass public
I have a class that implements the IDisposable interface. I am using a webclient
We have the following class hierarchy: public interface IManager { object GetObject(int); } public
Say, I have such classes hierarchy: public interface IRepository { } public class SomeSimpleRepository
I have an abstract class, AbsClass that implements an interface, IClass . IClass has
I have this class hierarchy: public interface ISR { } public interface ICU {
I have this type of class hierarchy: public interface IA{} public interface IB{void Foo();}
I have a class which implements the following interface: IUser { string UserName {
Say I have my class @interface Person : NSObject { NSString *name; } I
I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.