I have several queries identical except for the subject and parameters of the query and I am trying to formulate a 'generalised' query to avoid multiple lines of almost identical code.
I have the following code:
Code Snippet
private IEnumerable doQuery(string rangeVar,
DataSet dsSubTable,
string qrySubject,
string subTableKey,
string subTableDescription,
string fldName)
{
qryStart = dtmpickFrom.Value;
qryEnd = dtmpickTo.Value;
var groupQuery =
from trans in dataSet.Transaction
where ((trans.T_Date >= qryStart) && (trans.T_Date <= qryEnd))
from rangeVar in dataSet.dsSubTable <<<<<<
where trans.qrySubject == rangeVar.subTableKey
select new ..... <snipped>
The compiler won't accept the dsSubTable (shown <<<<<) with the following message:
'ExpenditureLINQDataSets.Expenditure' does not contain a definition for 'dsSubTable' and no extension method 'dsSubTable' accepting a first argument of type 'ExpenditureLINQDataSets.Expenditure' could be found (are you missing a using directive or an assembly reference?)'
I realise this, of course (if I try to give dsSubTable a type of Expenditure..... only the actual table names defined in my DataSet appear in Intellisense.)
Is it possible to generalise such LINQ queries or must I live with multiple, allmost identical queries in my code?
Any assistance appreciated!