Determine the number of records a table hasq RRS feed

  • Question

  • Hi:

    I have the following linq query in a function:




    q = from c in DataContext.Customers select c;



    return q.Count();

    I'd like to do two things, firstly allow the user to select the table for which they want the number of records, and secondly, is this the most

    efficient way of doing this, I tried to use ExecuteQuery, but don't seem to be able to for this type of query, and I don't really want to have to utilise an connection just for this!

    esentially what I want in sql terms is:

    select count(*) from table, where table is specified by the user.

    Hope somebody can help.




    Thursday, November 18, 2010 7:49 AM

All replies

  • Hello,

    To return number of records, you may try with:

    return datacontext.Customers.Count();

    It returns the same TSql query as your linq query but a littble bit more terse.

    May ask why did you need to specify the table at runtime by user?


    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact
    Saturday, November 20, 2010 6:49 AM