Search through multiple lists, but have functions that do that in parts I have an Entity Framework table of Addresses. I'm building a Repository that would allow me to search for an Address by either parts of the Address or the whole address.

Here's what I've got so far:

public class AddressRepository : Repository&lt;Address&gt;
{
    public List&lt;Address&gt; GetByAddress(string street, string city, string state, string zip)
    {
        return DbSet
            .Where(address =&gt; address.Street.Contains(street))
            .Where(address =&gt; address.City.Contains(city))
            .Where(address =&gt; address.State.Contains(state))
            .Where(address =&gt; address.Zip.Contains(zip))
            .ToList();
    }

    public List&lt;Address&gt; GetByStreet(string street)
    {
        return DbSet.Where(address =&gt; address.Street.Contains(street)).ToList();
    }

    public List&lt;Address&gt; GetByCity(string city)
    {
        return DbSet.Where(address =&gt; address.Street.Contains(city)).ToList();
    }

    public List&lt;Address&gt; GetByState(string state)
    {
        return DbSet.Where(address =&gt; address.Street.Contains(state)).ToList();
    }

    public List&lt;Address&gt; GetByZip(string zip)
    {
        return DbSet.Where(address =&gt; address.Street.Contains(zip)).ToList();
    }
}


Here is my Repository base class:

public class Repository&lt;T&gt; where T : class
{
    private readonly ApplicationDbContext _applicationDbContext = new ApplicationDbContext();

    protected DbSet&lt;T&gt; DbSet { get; }

    protected Repository()
    {
        DbSet = _applicationDbContext.Set&lt;T&gt;();
    }

    public virtual List&lt;T&gt; GetAll()
    {
        return DbSet.ToList();
    }

    public virtual T Get(int id)
    {
        return DbSet.Find(id);
    }

    public virtual void Add(T entity)
    {
        DbSet.Add(entity);
    }

    public virtual void SaveChanges()
    {
        _applicationDbContext.SaveChanges();
    }
}


Now, I'm thinking that in my GetByAddress function I should be calling my GetByStreet/City/State/Zip functions instead of repeating their code.

I haven't quite figured out how to do that, so any help or suggestions regarding that would be great.

As a side question: In my Repository class I have a GetAll function that returns the whole DbSet as a list, should I be calling GetAll().Where(...) instead of calling DbSet.Where(...)?
I would suggest that you don't use a repository at all. You already have a library that handles abstracting the database. You don't need the repository abstraction. And if you need some kind of abstraction, use a query object.

Some extensions are handy to build the query:

public static class AddressQueryExtensions
{
    public static IQueryable&lt;Address&gt; WhereStreetContains(this IQueryable&lt;Address&gt; query, string street)
    {
        return query.Where(address =&gt; address.Street.Contains(street));
    }

    public static IQueryable&lt;Address&gt; WhereCityContains(this IQueryable&lt;Address&gt; query, string city)
    {
        return query.Where(address =&gt; address.City.Contains(city));
    }

    public static IQueryable&lt;Address&gt; WhereStateContains(this IQueryable&lt;Address&gt; query, string state)
    {
        return query.Where(address =&gt; address.State.Contains(state));
    }

    public static IQueryable&lt;Address&gt; WhereZipContains(this IQueryable&lt;Address&gt; query, string zip)
    {
        return query.Where(address =&gt; address.Zip.Contains(zip));
    }
}


These can be combined however you want:

var addresses = DbSet
    .WhereStreetContains(street)
    .WhereCityContains(city)
    .WhereZipContains(zip)
    .Where(x =&gt; x.State == null)
    .ToList();


Some reading regarding repositories and ORMs.

https://lostechies.com/jimmybogard/2012/09/20/limiting-your-abstractions/
https://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/
https://ayende.com/blog/3955/repository-is-the-new-singleton