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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:05:57+00:00 2026-06-06T08:05:57+00:00

I found many examples of generic repository using LINQ to SQL. However there is

  • 0

I found many examples of generic repository using LINQ to SQL. However there is not enough examples about how to call these functions. Can you please provide an example about how to use the following functions by a client?

Note: My question is about the use of Func T,bool. What are the possible ways to use it?

Note: BankAccount is an entity.

class MyRepository<T> : IRepository<T> where T : class
{
    ..........

    public IEnumerable<T> FindAll(Func<T,bool> predicate)
    {
        return Context.GetTable<T>().Where(predicate);
    }

    public T FindByID(Func<T,bool> predicate)
    {
        return Context.GetTable<T>().SingleOrDefault(predicate);
    }
}

EDIT

Based on response, I used it as follows;

 public RepositoryLayer.Account FindFirstAccount()
    {
        Func<RepositoryLayer.Account, bool> predicate = (p => p.AccountNumber == 1);
        List<RepositoryLayer.Account> accList =  (accountRepository.FindAll(predicate)).ToList();
        return accList[0];
    }

Note: List RepositoryLayer.Account accList = (List RepositoryLayer.Account) accountRepository.FindAll(predicate); will not 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-06-06T08:05:58+00:00Added an answer on June 6, 2026 at 8:05 am

    There are a few ways to specify Func, which is in essence a delegate which takes one parameter and returns a bool.

    The most convenient way in most situations is to specify it as a Lambda expression, such as:

    var repo = new Repository<BankAccount>();
    repo.FindById(account=>account.Id == 15);
    

    The other ways of specifying Func are best described here.

    EDIT:
    To fix your latest error, you need the results as List. Remove your explicit cast and try:

    accountRepository.FindAll(predicate).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've found many examples about UTC tables and php date methods to convert it,
I found many examples for older versions of CherryPy but they each referenced importing
I've found many examples on how to search for files that exist in a
I have a problem with writing a Cartesian power function. I found many examples
I'm learning about loop unrolling to avoid stalls caused by dependencies. I found many
Firstly, I have found many examples of how to grab data from a db
I have found many examples of how to match particular types of URL-s in
I need to simulate Poisson wait times. I've found many examples of simulating the
I was reading other questions posted and found many examples to retrieve last month
I've searched for this in a long time now, and there are many examples

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.