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 1062061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:34:00+00:00 2026-05-16T18:34:00+00:00

I have an interface contract that looks like this: ICollection<FooBar> FindByPredicate(Expression<Func<FooBar,bool>> predicate); ICollection<Foo> FindByPredicate(Expression<Func<Foo,bool>>

  • 0

I have an interface contract that looks like this:

ICollection<FooBar> FindByPredicate(Expression<Func<FooBar,bool>> predicate);
ICollection<Foo> FindByPredicate(Expression<Func<Foo,bool>> predicate);
ICollection<Bar> FindByPredicate(Expression<Func<Bar,bool>> predicate);

Foo and Bar are concrete classes which inherit from the FooBar abstract class.

Now, im running into problems when trying to invoke these methods:

var foo = myService.FindByPredicate(f => f.UserId == 1);

It’s getting “Ambigious invocation” errors, which kind of makes sense, because the property “UserId” exists on the abstract “FooBar” type (and thus exists on Foo and Bar as well).

So, how can i overcome this?

I like the look of my interface (overloaded predicate methods) as from an intellisense point of view from the calling code, there is only one method name.

Why do i have my interface like that? Well, some scenarios i wish to return only “Foo” or “Bar”, other times i need a mixed bag, hence i need to return the abstract type – make sense?

Anyway, onto the obvious question – is there a way around this? (other than renaming my interface methods)? (and thus compromising the simplicity)

  • 1 1 Answer
  • 1 View
  • 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-05-16T18:34:01+00:00Added an answer on May 16, 2026 at 6:34 pm

    You can declare the method to be generic, and then you need only one method:

    public interface IFooBarService
    {
        ICollection<T> FindByPredicate<T>(Expression<Func<T, bool>> predicate)
            where T : FooBar;
    }
    

    and then you can call it like this:

    var foo = myService.FindByPredicate<Foo>(f => f.UserId == 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, I have an URL that looks for an image like this: http://example.com/img/foo.png
I have a very simples Hello World WCF Service, that looks like this: namespace
This question was asked at interview. Say I have a contract. [ServiceContract] public interface
Ok so I have two objects that look like this in my WCF service.
I have a interface as follows: namespace Contract { [InheritedExport(typeof(ITransform))] public interface ITransform {
Let's say I have a WCF contract such as [ServiceContract] public interface IContract {
I have a service with multiple contracts like so. [ServiceContract] public partial interface IBusinessFunctionDAO
I have interface Foo public interface Foo { public void test(); } Class FooChild
Let's say we have interface window_creator that responsible for creation of windows. For simplicity
I'm trying to figure out why this code won't compile. I have interface A

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.