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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:07:06+00:00 2026-06-18T13:07:06+00:00

i have the following function public virtual ICollection<T> initData<T>(System.Data.Entity.DbSet<T> set, System.Linq.Expressions.Expression<Func<T, bool>> filter) where

  • 0

i have the following function

public virtual ICollection<T> initData<T>(System.Data.Entity.DbSet<T> set, System.Linq.Expressions.Expression<Func<T, bool>> filter) where T : CModel<T>
        {
            var x = (from dc in set select dc);
            if (!this.db.valid)
            {
                System.Linq.Expressions.Expression<Func<T, bool>> active = a => a.active;
                filter = (Expression<Func<T, bool>>)Expression.Lambda(Expression.AndAlso(filter, active));
                x.Where(filter);

            }
            else
            {
                x.Where(filter);
            }
            return (ICollection<T>)x.ToList();
        }

when ever i try to combine the 2 predicates with AndAlso i throws an exception :

The binary operator AndAlso is not defined for the types 'System.Func`2[namespace.Models.MyClass,System.Boolean]' and 'System.Func`2[namespace.Models.MyClass,System.Boolean]'.

how can i combine these two conditions?

  • 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-18T13:07:07+00:00Added an answer on June 18, 2026 at 1:07 pm

    I think you are making life hard for yourself. You could just use the Where extension method multiple times like this:

    public virtual ICollection<T> initData<T>(System.Data.Entity.DbSet<T> set, System.Linq.Expressions.Expression<Func<T, bool>> filter) where T : CModel<T>
    {
        var x = (from dc in set select dc);
        x = set.Where(filter);
    
        if (!this.db.valid)
        {
            x = x.Where(a => a.active);
        }
    
        return x.ToList();
    }
    

    Note that in your code you used x.Where(filter);
    This is useless because Where does not mutate x, so the result is basically discarded.
    To keep the result you need to assign it to something:
    x = x.Where(filter);.
    This is the same idea as when you are working with strings.

     

    Second answer:

    There is a built in delegate called Predicate<T>. I think you might have more luck using this type than the Func<T, bool>, even though they both essentially have the same meaning. I think that be what the compiler error was trying to say.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function: public static byte[] StringToByte(string str) { int length =
I have the following function: public static T TryGetArrayValue<T>(object[] array_, int index_) { ...
I have the following function below: public function setupHead($title){ $displayHead .='<!DOCTYPE html PUBLIC -//W3C//DTD
I have following function in one Activity public void AppExit() { Editor edit =
I have following repository: public function findClassPhotoByPath($path) { return $this->getEntityManager() ->createQuery('SELECT p FROM KSRGalleryBundle:Photo
I have the following higher-order function: public static Func<T, bool> Not<T>(Func<T, bool> otherFunc) {
I have the following function for SQLite select statement public Boolean itemFound(String cartId,Long ItemId){
I have the following function which sets up the GUI. public void go() {
I have the following Symfony2 form: public function buildForm(FormBuilder $builder, array $options) { $builder
I have the following piece of code in my Model: public function getSite() {

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.