Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 895317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:32:22+00:00 2026-05-15T14:32:22+00:00

In .NET 4.0 and Linq to SQL, I am trying to use a partial

  • 0

In .NET 4.0 and Linq to SQL, I am trying to use a partial class to “trigger” changes from within an update method (an existing DBML method). For simplicity, imagine a table Things with columns Id and Value

The auto gen DBML contains a method OnValueChanged, I’ll extend that and as an exercise try to change one value in one other row :

   public partial class Things
    {
        partial void OnValueChanged()
        {
            MyAppDataContext dc = new MyAppDataContext();
            var q = from o in dc.GetTable<Things>() where o.Id == 13 select o;
            foreach (Things o in q)
            {
                o.Value = "1";  // try to change some other row
            }
            try
            {
                dc.SubmitChanges();
            }
            catch (Exception)
            {
                // SQL timeout occurs 
            }
        }
    }

A SQL timeout error occurs. I suspect that the datacontext is getting confused trying to SubmitChanges() before the current OnValueChanged() method has disposed of it’s datacontext, but I am not sure.

Mostly I cannot find an example of a good pattern for triggering updates against a DB within an existing DBML generated method.

Can anyone provide any pointers on why this doesn’t work and how I can accomplish something that works OK? (I realize I can trigger in the SQL database, but do not want to take that route.)

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:32:23+00:00Added an answer on May 15, 2026 at 2:32 pm

    First, you aren’t disposing of the DataContext at all in your function. Wrap it in a using statement.

    The actual issue is coming from the fact that you’re recursively calling yourself by setting the Value property on the retrieved values. You’re just running into the timeout before you can hit a StackOverflowException.

    It’s unclear what you’re trying to do here; if you’re trying to allow different behavior between when you set the Value property here versus anywhere else, then it’s simple enough to use a flag. In your partial class, declare an internal instance boolean auto property called UpdatingValue, and set it to true on each item inside your foreach block before you update the value, then set it to false after you update the value. Then, as the first line in OnValueChanged, check to ensure that UpdatingValue is false.

    Like this:

    public partial class Things
    {
         internal bool UpdatingValue { get; set; }
    
         partial void OnValueChanged()
         {
             if (UpdatingValue) return;
    
             using(MyAppDataContext dc = new MyAppDataContext())
             {
                 var q = from o in dc.GetTable<Things>() where o.Id == 13 select o;
                 foreach (Things o in q)
                 {
                     o.UpdatingValue = true;
                     o.Value = "1";  // try to change some other row
                     o.UpdatingValue = false;
                 }
    
                 dc.SubmitChanges();
             }
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use LINQ to SQL Server in C#/.NET on Visual Studio 2010.
My app in ASP.NET C#, i use linq to sql to pass data from
With .NET, which data access method is better to use LINQ to SQL,entity framework,
I'm experimenting some difficulties trying to use Connection String Builders (ADO.NET) within LINQ to
Link I'm using ASP.NET with C# and trying to use linq to sql to
I'm using Linq to SQL within an ASP.NET MVC application. The model consists of
My app in ASP.NET C#. I use Linq to Sql, look the picuture //
I'm simply trying to get data from two sql server db tables using ado.net
I am new to asp.net and I am trying to learn Linq to SQL.
I am trying out Linq to SQL in an ASP.NET application that uses a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.