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

  • Home
  • SEARCH
  • 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 654415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:29:31+00:00 2026-05-13T22:29:31+00:00

I have a interface resembling the following: public IEnumerable<IDocument> Search(Predicate<IDocument> predicate) { … }

  • 0

I have a interface resembling the following:

public IEnumerable<IDocument> Search(Predicate<IDocument> predicate) { ... }

where an IDocument looks like this:

public interface IDocument 
{
    string Id {get; set;}
    string Title {get; set;}
    ...
}

I am about to implement a document provider where I have to decompose the content of the Predicate and extract the properties in order to make an SQL string for a document database to which we currently have no OR/M mapping. An example: I want to know if the user is searching by ID or by Title so I know if I can search by ID or have to perform a LIKE search on Title.

I’ve always used LINQ heavily but this is the first time I’m sitting in the other end of the pipeline… I’ve read up a bit on Expression trees and Reflection but the pieces haven’t fallen in place yet. How (if?) can I decompose/reflect the Predicate so I get a list of parameters which I can concactate into an SQL string? I am looking for something like this rough sketch:

public IEnumerable<IDocument> Search(Predicate<IDocument> predicate) 
{ 
    string id = DoSomeMagic(predicate, "Id");
    string title = DoSomeMagic(predicate, "Title");
    if (!string.isNullOrEmpty(id))
       ...make ID search
    else
       ...search by title
}

Disclaimer: The provider is for an inhouse legacy system bound for replacement this fall which makes inline SQL a proper choice ;o)

  • 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-13T22:29:31+00:00Added an answer on May 13, 2026 at 10:29 pm

    You can’t easily introspect the predicate. Maybe you should consider changing your design into a more ad hoc predicate type, a more specific predicate interface :

        public interface IDocument 
        {
            string Id {get; set;}
            string Title {get; set;}
        }
        public class SearchCriteria
        {
            public Nullable<int> Id;
            public string Title;
        }
        public IEnumerable<IDocument> Search(SearchCriteria predicate)
        {
            if (predicate.Id.HasValue)
                //...make ID search
            else if (!string.IsNullOrEmpty(predicate.Title))
                //...search by title
            else
                // other kind of search
        }
    

    Replace the public fields with attributes, put the search logic in the SearchCriteria (e.g. .GetResult() or .GetSQLQuery()) and this may fit your system, assuming you can know all the available search criteria.

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

Sidebar

Related Questions

I have next interface public interface IMyInterface { string this[string key] { get; set;
I have an Interface like this: namespace QuickRoutes.Model.Utilities { public interface IRoutesManager { bool
I have interface defs like below. public interface IProvider { } public interface IProviderList
Let's say I have interface IMatrix { double this[int r, int c] { get;
Let's say I have interface: public interface IFoo { int Bar1 { get; set;
I have interface IConfigurationSource { .... } and class FileConfigurationSource : IConfigurationSource { FileConfigurationSource(string
I have interface Foo public interface Foo { public void test(); } Class FooChild
I'm trying to figure out why this code won't compile. I have interface A
I have an interface: public interface: IA { ... } and I try to
I have interface: public interface CartService extends RemoteService{ <T extends ActionResponse> T execute(Action<T> action);

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.