I have a supplying method in DAL:
public IEnumerable GetRecords()
{
using (LinqDataContext context = new LinqDataContext())
{
1) yield
will not necessarily be faster to get all values, but it would allow the code to start handling results before the database has returned all results. That is, yield returns the first result the instant it shows up, while ToArray() needs to wait for all results to show up before returning. Of course, if the underlying providers return all results at once due to buffering or other reasons, this may not make a difference.
2) Yes, using
will dispose of the LinqDataContext no matter how you exit the using block (exceptions/return/break/...)