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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:26:28+00:00 2026-05-13T13:26:28+00:00

I have the following method I can pass in a lambda expression to filter

  • 0

I have the following method I can pass in a lambda expression to filter my result and then a callback method that will work on the list of results. This is just one particular table in my system, I will use this construct over and over. How can I build out a generic method, say DBget that takes a Table as a parameter(An ADO.NET dataservice entity to be fair) and pass in a filter (a lambda experssion).

 public void getServiceDevelopmentPlan(Expression<Func<tblServiceDevelopmentPlan, bool>> filter, Action<List<tblServiceDevelopmentPlan>> callback)
        {
            var query = from employerSector in sdContext.tblServiceDevelopmentPlan.Where(filter)
                        select employerSector;


            var DSQuery = (DataServiceQuery<tblServiceDevelopmentPlan>)query;
            DSQuery.BeginExecute(result =>
            {
                callback(DSQuery.EndExecute(result).ToList<tblServiceDevelopmentPlan>());

            }, null);

    }

My first bash at this is:

public delegate Action<List<Table>> DBAccess<Table>(Expression<Func<Table, bool>> filter);
  • 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-13T13:26:29+00:00Added an answer on May 13, 2026 at 1:26 pm

    If you are using Linq to Ado.NET Dataservices or WCF Dataservices, your model will build you a lot of typed. Generally though you will be selecting and filtering. You need the following, then all your methods are just candy over the top of this:

    Query Type 1 – One Filter, returns a list:

    public  void makeQuery<T>(string entity, Expression<Func<T, bool>> filter, Action<List<T>> callback)
        {
            IQueryable<T> query = plussContext.CreateQuery<T>(entity).Where(filter);
    
            var DSQuery = (DataServiceQuery<T>)query;
            DSQuery.BeginExecute(result =>
            {
                callback(DSQuery.EndExecute(result).ToList<T>());
            }, null);
    
        }
    

    Query Type 2 – One Filter, returns a single entity:

    public void makeQuery(string entity, Expression> filter, Action callback)
    {

            IQueryable<T> query = plussContext.CreateQuery<T>(entity).Where(filter);
            var DSQuery = (DataServiceQuery<T>)query;
            DSQuery.BeginExecute(result =>
            {
                callback(DSQuery.EndExecute(result).First<T>());
            }, null);
    
        }
    

    What you need to do is overload these and swap out the filter for a simple array of filters

    Expression<Func<T, bool>>[] filter
    

    And repeat for single and list returns.

    Bundle this into a singleton if you want one datacontext, or keep track of an array of contexts in some sort of hybrid factory/singleton and you are away. Let the constructor take a context or if non are supplied then use its own and you are away.

    I then use this on a big line but all in one place:

    GenericQuery.Instance.Create().makeQuery<tblAgencyBranches>("tblAgencyBranches", f => f.tblAgencies.agencyID == _agency.agencyID, res => { AgenciesBranch.ItemsSource = res; });
    

    This may look complicated but it hides a lot of async magic, and in certain instances can be called straight from the button handlers. Not so much a 3 tier system, but a huge time saver.

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

Sidebar

Ask A Question

Stats

  • Questions 534k
  • Answers 534k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can set the initial property via the __init___ method.… May 17, 2026 at 12:56 am
  • Editorial Team
    Editorial Team added an answer As Matthew said, 18.565 can't be accurately represented. The actual… May 17, 2026 at 12:56 am
  • Editorial Team
    Editorial Team added an answer Here you're getting a reference to the result of get_post($id).… May 17, 2026 at 12:56 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
Is there a way to use the CompiledQuery.Compile method to compile the Expression associated
I have a couple questions about Ruby's methods, procedures, and blocks that strike me
Using shoulda with unit/test I have a context which requires one test to pass
Hello friends i am to add optional parameter to pass these in a method
I have a REST service that I'm trying to call. It requires something similar
Let's say we have a simple F# quotation: type Pet = { Name :
I have a Python Facebook project hosted on Google App Engine and use the
First, I have never used SWIG, I dont know what it does... We have
I have a String Array in a java program. I am using jdbc driver

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.