posts - 218, comments - 222, trackbacks - 68

My Links

News




I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net) and born in Bangladesh.
I work for Ocean Informatics Pty Ltd as a Senior Developer - Analyst.
I am also co-founder and core developer of Pageflakes (acquired by LiveUniverse) www.pageflakes.com
and most recently created SmartCodeGenerator

My Articles
Flexible and Plugin based .Net Application..
Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker'
Write your own Code Generator or Template Engine in .NET
Smart Code Generator .NET: Usage Overview
Smart Code Generator .NET: Architectural Overview
Smart Code Generator .NET: using with NAnt and Cassini

Archives

Free Programming Language Training

LINQ Tips: Querying disposable objects in an using block

Be careful while querying the disposable object inside an using block, you may find that the yielded objects are all disposed before you have used them. To get over this issue use the ToList() method. You can exit the using block, and yield the results out.

Example:

IEnumerable<Student> results;
using (var db = new StudentDataContext())
{
  results = db.Students.Where(...).ToList();
}
foreach (var student in results)
{
  SomeMethod(student);
  yield return student;
}

Print | posted on Tuesday, February 05, 2008 1:33 PM |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 7 and 3 and type the answer here:

Powered by: