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 926721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:43:50+00:00 2026-05-15T19:43:50+00:00

My Title may be slightly off but here is what I am trying to

  • 0

My Title may be slightly off but here is what I am trying to do. I have a L2S Method that would be for every table that I would like to write once. This is to set a soft lock column where I will also need a Read and UnLock method. Here is what I have so far:

public static void LockRow(string TableName, int TablePrimaryKey)
    {
        using (var context = McpDataContext.Create())
        {
            var tableToLock = (from lockTable in context.tblPlans
                               where lockTable.PlanID == TablePrimaryKey
                               select lockTable).Single();

            tableToLock.Locked = true;
            context.SubmitChanges();
        }
    }

What I would like to do is replace context.tblPlans with context.TableName. Is this possible in LINQ? How so? I am assumming that I am going about it the wrong way so I’d be grateful for some direction/pointers.

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-15T19:43:51+00:00Added an answer on May 15, 2026 at 7:43 pm

    Update becuase the first example would not work.

    You could do it with a generic method and an interface:

    public interface IPlanTable
    {
        int PlanID { get; set; }
    }
    
    public static void LockRow<TEntity>(int TablePrimaryKey) where TEntity : class, IPlanTable
    {
        using (var context = McpDataContext.Create())
        {
            var tableToLock = (from lockTable in context.GetTable<TEntity>()
                               where lockTable.PlanID == TablePrimaryKey
                               select lockTable).Single();
    
            tableToLock.Locked = true;
            context.SubmitChanges();
         }
    }
    

    You will also have to use the fact that the Linw2SQL tables are created as partial classes to extend them so all the relevent table implement IPlanTable

    You would use it like below:

    LockRow<tblPlan>(23); 
    

    simply replace tblPlan with whatever the name of your table class is.

    However this won’t allow you to set the table at runtime, LinqToSQL is object orientated and type safe, specifying the table you want to retreive is contrary to how it si designed to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I may of got the Title slightly wrong but basically, I have two cells.
The title may be a bit vague, but here's my goal: I have a
Okay the title may not justify what I'm trying to do here but dont
Title may be confusing, but here's explanation with code. Based on some conditions, I
The title may have been confusing, but please let me explain: Currently when I
The title may sound confusing. But here's my issue. I want to show something
The title may be misleading. I have the following A custom user control that
I know that the title may be confusing (or even misleading), but I'm planning
My title may make my question sound confusing, but it is not. I have
The question's title may sound stupid, but I have beenw wondering about the following

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.