To LINQToDataSets Team: can I do this (please ????) RRS feed

  • Question

  • I have 3 queries identical except for the subject of the query and I am trying to 'generalise' the query to avoid multiple lines of almost identical code, (which I can do with any other aspect of C#.)

    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 etc appear in Intellisense.)

    Surely it's possible to parameterise such a query.

    How would I solve this problem?

    Any assistance appreciated!

    Friday, December 5, 2008 11:41 PM

All replies

  • Mmmm, still no replies so

    (a) it can't be done, in which case so much for code reuse

    (b) it can, but nobody knows how, in which case there appears to be a dearth of understandable examples/documentation (I can't find any which address this particular issue and, believe me, I've searched)

    (c) it can, but nobody is prepared to help in which case so much for the spirit of friendly assistance
    Monday, December 8, 2008 8:49 PM