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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:31:59+00:00 2026-06-05T00:31:59+00:00

In my interface I have following defined List<IFoo> GetListOfFoo<T>(Expression<Func<T, bool>> predicate) where T :

  • 0

In my interface I have following defined

List<IFoo> GetListOfFoo<T>(Expression<Func<T, bool>> predicate) where T : IFoo;

In my implementation I’ll cast the expression in the specific type:

if (typeof(T) == typeof(Foo))
{
    Expression converted = Expression.Convert(predicate.Body, typeof(Foo));
    Expression<Func<Foo, bool>> newPredicate = 
        Expression.Lambda<Func<Foo, bool>>(converted, predicate.Parameters);
}

I try to use my implementation like this:

Expression<Func<Foo, bool>> predicate = c => c.Name == "Myname";
_repository.GetListOfFoo<Foo>(predicate);

I get no compiling errors, but if I use this, I get an Exception that in the ExpressionBody is the bool argument defined.

Where is my problem?

  • 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-05T00:32:01+00:00Added an answer on June 5, 2026 at 12:32 am

    I found a better solution. I don’t need to cast the predicate themselves.

    public List<IFoo> GetFoos<T>(Expression<Func<T, bool>> predicate) where T : class, IModel 
    {
        var result = new List<IFoo>();
        var repository = new Repository<T>();
        result.AddRange(repository.GetEntities(predicate).ToList().ConvertAll(c => (IFoo)c));
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined the following interface in F# [<ServiceContract>] type ICarRentalService = [<OperationContract>] abstract
I have the following interface defined to expose a .NET class to COM: [InterfaceType(ComInterfaceType.InterfaceIsDual)]
I have defined the following Interface [ServiceContract] public interface IHealthProducts { [OperationContract()] ResponseClass OrderSelfSignedHealthCertificate();
I have the following interface that returns the generic parameter of type T using
I have a C# interface defined as so: public interface IMenuSecurityService { void SetSecurityFlags(List<MenuItem>
I have the following interfaces defined: public interface IAudit { DateTime DateCreated { get;
I have the following class & interface defined: public interface A { } public
I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,
If use MongoRepository, You can have following code: @Repository public interface UserRepo extends MongoRepository<User,
I have the following interface: public interface ICalculationRule { public void calculate(EventBag eventBag); }

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.