views:

138

answers:

2

I have the following code which is in a base class.

        MyApp.MyDB = new MyApp.MyDB ();
        IRepository<T> repo = new SubSonicRepository<T>(db);
        CurrentTable = repo.GetTable();



        var s = db.SelectColumns(columnList.ToArray()).
                From(CurrentTable.Name).
                OrderAsc(CurrentTable.Descriptor.Name);

The idea is that all my classes can call this method.

I have just realised that I may need to a 'where' statement and there could be numerous columns names and values to test for.

What's the best approach for this?

UPDATE: I found this works below but is it best practice?

//WhereClause is a Dictionary<string, string>
        int count = 0;
        foreach (var whereitem in WhereClause)
        {
            if (count == 0)
            {
                s.Where(whereitem.Key).IsEqualTo(whereitem.Value);
            }

            else
            {
                s.And(whereitem.Key).IsEqualTo(whereitem.Value);
            }

            count++;
        }
+1  A: 

This simplifies the logic slightly: For the where clause, do something like this:

s.Where(1).IsEqualTo(1);

For all your other whereitem's, you can use And's.

sparks
A: 

I just always use "ands" ...

Mike Walsh