tags:

views:

9

answers:

0

Hi all,

I am using c# \ .net 3.5 and linqtosql (over an sql server dbms of course). I am using my data context for automic operations. I have a GetReadonly method of a factory method that returns me a new datacontext for each atomic operation.

I am able to perform CRUD operations well, though the following error occurs:

When I update or insert a class and then try to find the object by its new values, it doesn't appear. Although all of my linq operations are atomic (meaning that I create a new context for each select \ insert \ delete \ update method) the datacontext still doesn't consist of the most up to date values.

In my dbml designer filed I set all the columns' Update Check to never, yet since I am creating the datacontext each time I don't think that should be the cause of the problem?

Here's an example of DatacontextFactory.GetReadonly()

    private static myContext CreateDataContext()
    {
        string conn = string.Empty;
        System.Reflection.Assembly thisExe;
        thisExe = System.Reflection.Assembly.GetExecutingAssembly();
        System.IO.Stream file = thisExe.GetManifestResourceStream("Data.ConnectionString.txt");

        using (StreamReader sr = new StreamReader(file))
        {
            conn = sr.ReadToEnd();
        }

        myContext context = new myContext(conn);
        context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
            System.Data.Linq.DataLoadOptions loadOptions = new System.Data.Linq.DataLoadOptions();

        #region LoadOptions
        loadOptions.LoadWith<Image>(img => img.User);
        loadOptions.LoadWith<Vote>(vote => vote.Image);
        #endregion LoadOptions
        context.LoadOptions = loadOptions;
        return context;
    }

    public static myContext GetReadOnly()
    {
        myContext ReadonlyDataContext = CreateDataContext();
        ReadonlyDataContext.ObjectTrackingEnabled = false;
        return ReadonlyDataContext;
    }

Does anyone have an idea of what may be causing this?