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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:23:09+00:00 2026-05-17T20:23:09+00:00

I use Entity Framework 4. How can I perform a Generic Where Lambda Clause.?

  • 0

I use Entity Framework 4.
How can I perform a Generic Where Lambda Clause.?

I Have many Entity that need the same Where Query.

public Func<SupplierTypeText, bool> GetLmbLang()
{
    return (p => p.LangID == 1);
}


public Func<ProductText, bool> GetLmbLang()
{
    return (p => p.LangID == 1);
}


public Func<CategoryText, bool> GetLmbLang()
{
    return (p => p.LangID == 1);
}

I would like to have a generic method like

//public interface IRepository<T> : IRepository<T> where T : class
public Func<T, bool> GenericGetLmbLang()
{
    return (p => p.LangID == 1);
}

For the moment, I hardcoded Language ID == 1, that will be from the user session to make it dynamic.

That’s would be very usefull if I Can directly call the GetLmbLang() Directly in the Where clause.

 var ViewModel = _db.Suppliers.Select(model => new
            {
                model,
                SupType = _db.SupplierTypeTexts.Where(a => GenericGetLmbLang())
            });

——UPDATE——–

Here is what I Trying and nothing works.

My Base Class

 public class BaseGenericModel
    {
        public int LangID { get; set; }

        public Func<BaseGenericModel, bool> GetLmbLang()
        {
            return (p => p.LangID == 1);
        }

    }

My interface is

   public interface IBaseRepository<T> where T : BaseGenericModel
   {
        Func<T, bool> GetLmbLang();
   }


   public class BaseRepository<T> : IBaseRepository<T> where T : BaseGenericModel
   {

       public Func<T, bool> GetLmbLang()
       {
          return (p => p.LangID == 1);
       }
   }

I Can’t call this repository form my SupplierTypeText,ProductText,CategoryText. That’s doesn’t work.

  • 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-05-17T20:23:10+00:00Added an answer on May 17, 2026 at 8:23 pm

    It seems that you have three different types all having the LangID property. I would make them derive from a common base class where this property is defined:

    public class BaseClass
    {
        public int LangID { get; set; }
    }
    

    and then have a single method:

    public Func<BaseClass, bool> GetLmbLang()
    {
        return (p => p.LangID == 1);
    }
    

    An interface containing this property could also be used.

    If you want to make it generic you could but you will still need a generic constraint to indicate a common base type if you want to use the LangID property:

    public class SomeRepository<T> where T: BaseClass
    {
        public Func<T, bool> GetLmbLang()
        {
            return (p => p.LangID == 1);
        }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I use two different back ends for an .net Entity Framework project? I
I am developing a rich client application that will use the Entity Framework (with
i search a good tutorial to learn how to use entity framework in the
Is it possible to use Microsoft Entity Framework with Oracle database?
I'm planning to use MS entity framework for new web apps (come on EF
One of the much-anticipated features of Entity Framework 4 is the ability to use
I have a standard Domain Layer entity: public class Product { public int Id
We use a base entity with properties such as version (datetime needed for NHibernate)
Do you still use session or entity EJBs in your project? Why?
Castle Active Record? Plain NHibernate? Subsonic? Entity? Something like Nettiers? I'd like to use

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.