This is how to implement dispose pattern to file reading in C#: using System; using System.IO; class BaseResource: IDisposable { // Track whether Dispose has been called. private bool disposed = false; // The unmanaged resource wrapper object private FileStream file; // Class constructor public BaseResource(String fileName) { Console.WriteLine("BaseResource constructor allocates unmanaged resource wrapper"); file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); } // Implement IDisposable public void Dispose() { // Check to see if Dispose has already been called. if (!disposed) { Console.WriteLine("Dispose pattern releases unmanaged resource wrapper's resource"); file.Close(); disposed = true; } } public void Close() { Dispose(); } public void DoS
Today I've brought together with no way to insert item in Many-to-Many relationship based on Entity Framework
The decision was unexpected. I've missed to mark my primary keys in the intermediate table. That was all... Be carefull! http://weblogs.asp.net/kencox/archive/2009/09/09/fixing-the-system-data-updateexception-definingquery-and-no-lt-insertfunction-gt-error.aspx