locked
locking tables using linq

    Question

  • Hi,
    Is it possible lock an entire table using linq so that no updates or inserts are made at a particular interval?
    Tuesday, September 09, 2008 7:04 PM

Answers

  • Not really using L2S, but using the DC for db access... ...here's a crude table locker...

     

     

    Code Snippet

    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable }))
    {
        using (SomeDataContext dc = new SomeDataContext())
        {
            IEnumerable<string> version = (IEnumerable<string>)dc.ExecuteQuery(typeof(string), "select top 1 some_field from some_table with (tablockx)");

     

            //...do stuff...

        }
    }

     

     

     

     

    ...but why would you want to do that? (a soft semaphore/flag in a separate table is a friendlier way to do it)

    Wednesday, September 10, 2008 10:35 AM