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

  • Home
  • SEARCH
  • 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 872373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:46:31+00:00 2026-05-15T10:46:31+00:00

Assume I have a table called User . Using LINQ desinger, I will end

  • 0

Assume I have a table called User. Using LINQ desinger, I will end up with the following:

  • A file called User.dbml
  • A data context class called UserDataContext which subclasses from System.Data.Linq.DataContext
  • A class called User which is mapped from the User table. A UserDataContext object will have a property called Users which is of type System.Data.Linq.Table<User>.

So far so good. Now I want to define a generic base class that converts the Linq.Table property to JSON string for all of its subclasses. So I would have:

using Newtonsoft.Json;

class BasePlugin<T> where T : System.Data.Linq.DataContext, new()
{
    protected T DataContext = new T();
    protected string GetJSONData()
    {            
        //*** DataContext if of type System.Data.Linq.DataContext, therefore it won't know the Linq Table property of its subclasses
        return JsonConvert.SerializeObject(DataContext.Cannot_get_subclass_property_Linq_table);
    }
}

To complete the code in the question, here’s an example of a subclass:

class UserPlugin : BasePlugin<UserDataContext>
{
    //The protected member DataContext inherited from BasePlugin 
    //has a property called Users of type System.Data.Linq.Table<User>.
    //The point to to avoid implementing GetJSONData() in all subclasses
}

To summarize, the question is how to avoid implementing GetJSONData() in all subclasses by letting the base class do it.

  • 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-15T10:46:32+00:00Added an answer on May 15, 2026 at 10:46 am

    It’s not clear which table you’d want. There are potentially several tables in a single data context. There may not be in your particular model, but there certainly can be in LINQ to SQL in general.

    You can call DataContext.GetTable(Type) or DataContext.GetTable<T> if that’s useful… and you could parameterize your class by the entity type as well as the context type:

    class BasePlugin<TContext, TEntity> where TContext : DataContext, new()
        where TEntity : class
    {
        protected TContext DataContext = new TContext();
        protected string GetJSONData()
        {            
            return JsonConvert.SerializeObject(DataContext.GetTable<TEntity>());
        }
    }
    

    Is that what you’re after?

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

Sidebar

Related Questions

I have a table called Users in my database. Let's assume that User has
Assume we have a table called Persons and another table called Product_Orders. We will
Lets assume i have a table called VISITS containing the following VISIT_DATE (TIMESTAMP) HEIGHT
Assume I have a table called table and I have 3 columns, a, b,
Assume I have the following style table, col1 col2 and col3 have same value
I have a simple table called News . I'm using Entity Framework to generate
I have a column called image_small for a table images which will have information
suppose I have the following source table (called S): name gender code Bob 0
lets assume we have this table called visits and it has two fields id
Let's assume I have a table called normalize with an enum column called type

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.