I’ve been following the Tasky Case Study on the MonoDroid website, but I’ve run into a wall whilst creating a filtering and ordering query. I was wondering if somebody could explain where I might be going wrong please? I’m probably doing something completely backwards!
I get the error:
The type arguments for method ‘ICanTalk.BusinessLayer.Services.WordServices.Find(System.Func, System.Func, bool, int, int)’ cannot be inferred from the usage. Try specifying the type arguments explicitly.
I have the following code in one of my repositories, hopefully what I’m trying to do is kind of clear. I haven’t been able to build it yet to test to see if it works though:
public static IEnumerable<Word> Find<T,U>(Func<Word, bool> whereClause, Func<Word,U> orderBy, bool ascending, int show, int page)
{
int currentPage = page;
int resultsPerPage = show;
int skip = currentPage*show;
var result = ascending
? me.db.Find<Word>().Where(whereClause).OrderBy(orderBy).Take(resultsPerPage).Skip(skip)
: me.db.Find<Word>().Where(whereClause).OrderByDescending(orderBy).Take(resultsPerPage).Skip(skip);
return result;
}
From my services I call this method from here:
public static IList<Word> Find<T>(Func<Word, bool> whereClause, Func<Word,DateTime> orderBy, bool ascending, int show, int page)
{
return WordRepository.Find<Word, DateTime>(whereClause, orderBy, ascending, show, page).ToList();
}
What I’m trying to achieve is a call from an event handler within MonoDroid like:
var wordTest = WordServices.Find(x => x.ChildId == 3, x => x.AddedAt, true, 5, 1);
I had it almost right, I stripped it down to the basics and worked my way back up and came up with the following (compare to original if you’re interested).
SQLiteDatabase.cs
(not in original post – I scaled the query clauses right down to a reusable method in my generic handler):
WordRepository.cs
WordServices.cs
By this point I’m wondering why there exists a need for so many layers – will definitley look to refactor in the morning.
Originating Call