1

I have following class to override list methods:

public class As400Set<T> : List<T>
{
    public As400Set<T> Where(Expression<Func<T, bool>> expression)
    {
        //do something
    }

    public T SingleOrDefault(Expression<Func<T, bool>> expression)
    {
        //do something
    }
}

Everything works. So far so good. Now I want to extend the query with a select:

var item= context.Persons.Where(w => w.FirstName == "Hans").Select(s => s.LastName);

How can I override and the select method now? Is it even possible to query both methods one after the other?

What am I trying to achieve with my As400Set?

I am currently developing my own little OR mapper for our IBM system and would like to use it like EF. The where extension, for example, indicates the expression and query the database.

I also override for example the add method to set a changetracker state

    public new void Add(T entity)
    {
        // do something
        base.Add(entity);
    }

That's why I've derived from List so far

Sofpart
  • 25
  • 1
  • 8
  • 2
    This smells rather bad. You are not overriding anything here. `Where`, `FirstOrDefault`, etc. are extension methods. Why do you want to change the behavior of methods that everyone expects to behave in a certain way? This seems to be an XY problem. – InBetween Nov 28 '18 at 08:19
  • As an aside [you shouldn´t derive from `List`](https://stackoverflow.com/questions/21692193/why-not-inherit-from-listt). – MakePeaceGreatAgain Nov 28 '18 at 08:21
  • Thanks for the answers. I will read the thread why i shouldnt derive from List. I have also revised my question – Sofpart Nov 28 '18 at 08:37
  • You can create your own extension methods, like `public static IQueryable Where(this IQueryable source, Expression> predicate) { ... }`. You could control which extension method being used with the namespace, or you could use another name than simply `Where`. – Jeppe Stig Nielsen Nov 28 '18 at 08:47
  • Just a little update: I discarded the derivation of List and now work with IQueryable, and it is much better! Thank you – Sofpart Nov 30 '18 at 07:15

0 Answers0