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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:16:22+00:00 2026-05-14T18:16:22+00:00

I have an interface called ICatalog as shown below where each ICatalog has a

  • 0

I have an interface called ICatalog as shown below where each ICatalog has a name and a method that will return items based on a Predicate<Item> function.

public interface ICatalog
{
     string Name { get; }
     IEnumerable<Item> GetItems(Predicate<Item> predicate);
}

A specific implementation of a catalog may be linked to catalogs in various format such as XML, or a SQL database.

With an XML catalog I end up deserializing the entire XML file into memory, so testing each item with the predicate function does does not add a whole lot more overhead as it’s already in memory.

Yet with the SQL implementation I’d rather not retrieve the entire contents of the database into memory, and then filter the items with the predicate function. Instead I’d want to find a way to somehow pass the predicate to the SQL server, or somehow convert it to a SQL query.

This seems like a problem that can be solved with Linq, but I’m pretty new to it. Should my interface return IQueryable instead? I’m not concerned right now with how to actually implement a SQL version of my ICatalog. I just want to make sure my interface will allow for it in the future.

  • 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-14T18:16:23+00:00Added an answer on May 14, 2026 at 6:16 pm

    Rob has indicated how you might do this (although a more classic LINQ approach might take Expression<Func<Item,bool>>, and possbily return IQueryable<IFamily>).

    The good news is that if you want to use the predicate with LINQ-to-Objects (for your xml scenario) you can then just use:

    Predicate<Item> func = predicate.Compile();
    

    or (for the other signature):

    Func<Item,bool> func = predicate.Compile();
    

    and you have a delegate (func) to test your objects with.

    The problem though, is that this is a nightmare to unit test – you can only really integration test it.

    The problem is that you can’t reliably mock (with LINQ-to-Objects) anything involving complex data-stores; for example, the following will work fine in your unit tests but won’t work “for real” against a database:

    var foo = GetItems(x => SomeMagicFunction(x.Name));
    
    static bool SomeMagicFunction(string name) { return name.Length > 3; } // why not
    

    The problem is that only some operations can be translated to TSQL. You get the same problem with IQueryable<T> – for example, EF and LINQ-to-SQL support different operations on a query; even just First() behaves differently (EF demands you explicitly order it first, LINQ-to-SQL doesn’t).

    So in summary:

    • it can work
    • but think carefully whether you want to do this; a more classic black box repository / service interface may be more testable
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface called Dictionary which has a method insert() . This interface
I have an Interface called IStep that can do some computation (See Execution in
I have a property called IsSecureConnection that is part of my object's interface. This
I have an interface called IAddress, and a class called Address that handles street,
I have an interface for Client Registration called IRegistrationService. This contains one method called
I have an interface with a method Validate() and an abstract class that implement
I have an interface called ICommand from which various classes inherit. These classes all
I'm having a small problem in Java. I have an interface called Modifiable. Objects
If I have interface IFoo, and have several classes that implement it, what is
Lets say you have interface definition. That interface can be Operation . Then you

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.