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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:16:27+00:00 2026-05-14T07:16:27+00:00

I have many tables with identical schemas but different names. Can I create a

  • 0

I have many tables with identical schemas but different names. Can I create a single representative DBML/DataContext and re-use it for all the tables, or do I have to drag every table into the dbml designer?

  • 1 1 Answer
  • 1 View
  • 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-14T07:16:28+00:00Added an answer on May 14, 2026 at 7:16 am

    It is possible to do this without dragging every table from the designer, BUT it’s a PITA because you have to manually define all the table mappings for each subsequent object (which is what the DBML designer is doing for you, in essence). Here’s an example:

    Define a pair of tables:

    create table Person (
        Id int identity not null,
        Name varchar(50),
        Email varchar(50),
        constraint PK_Person primary key (Id)
    )
    
    create table OtherPerson (
        Id int identity not null,
        Name varchar(50),
        Email varchar(50),
        constraint PK_OtherPerson primary key (Id)
    )
    

    Add some data to them:

    Person
    Id  Name    Email
    1   Fred    fred@yabbadabba.com
    2   Wilma   wilma@yabbadabba.com
    
    OtherPerson
    Id  Name    Email
    1   Barney  barney@rubble.com
    2   Betty   betty@rubble.com
    

    Create a DBML file called TestsDb, and drag the Person table onto the surface. Now create the following partial class:

    partial class TestsDbDataContext
    {
        public System.Data.Linq.Table<OtherPerson> OtherPersons
        {
            get { return this.GetTable<OtherPerson>(); }
        }
    }
    

    For convenience, I used ReSharper to extract an interface from Person, like so:

    public interface IPerson
    {
        int Id { get; set; }
        string Name { get; set; }
        string Email { get; set; }
    }
    

    And then I created a new class called OtherPerson which implements that interface:

    [Table(Name = "dbo.OtherPerson")]
    public class OtherPerson : IPerson
    {
        [Column(AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY",
                IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id { get; set; }
    
        [Column(DbType = "VarChar(50)")]
        public string Name { get; set; }
    
        [Column(DbType = "VarChar(50)")]
        public string Email { get; set; }
    }
    

    And test it all in a main function like so:

    class Program
    {
        static void Main()
        {
            var dc = new TestsDbDataContext();
    
            var persons = dc.Persons.ToList().OfType<IPerson>();
            writePeople(persons);
    
            var otherPersons = dc.OtherPersons.ToList().OfType<IPerson>();
            writePeople(otherPersons);
        }
    
        private static void writePeople(IEnumerable<IPerson> people)
        {
            foreach (var person in people)
            {
                Console.WriteLine("{0}: {1} ({2})", person.GetType().Name,
                                  person.Name, person.Id);
            }
        }
    }
    

    And this is the end result:

    Person: Fred (1)
    Person: Wilma (2)
    OtherPerson: Barney (1)
    OtherPerson: Betty (2)
    

    As you can see, it’s possible, but is it really worth it? I suppose it might be worth it if you had some sort of automatic code generation going on (as opposed to manual code generation triggered by editing the DBML file), but otherwise, probably not.

    You could use the Entity framework though. I’m not too familiar with it, but I think it’s supposed to handle this sort of thing quite nicely, and EF4 is out now too.

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

Sidebar

Related Questions

I have many tables that use Lookup/Enum references for most of their column values.
I have created many tables using <table> tag but don't know how to get
I have many tables that have same number of columns and names because they
In my database, I have many tables which has the column StudentId, how can
I see this question have been asked in many different ways, but I don't
I have two tables with identical fields that share many rows. I'd like to
I have many tables, say T1, T2, T3. Every table has a column named
Does anyone has any insight on organizing sqlalchemy based projects? I have many tables
I have exported many times tables from Hive to SQL Server. I never face
I have a DB with many tables and one of the table has fields:

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.