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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:38:44+00:00 2026-05-11T09:38:44+00:00

(Follow-Up-Question to How to change LINQ O/R-M table name/source during runtime? ) I need

  • 0

(Follow-Up-Question to How to change LINQ O/R-M table name/source during runtime?)

I need to change the table source of a LINQ 2 SQL O/R-Mapper table during runtime. To achieve this, I need to create an XmlMappingSource. On command line, I could use SqlMetal to create this mapping file, but I would like to create the mapping file during runtime in memory. The XmlMappingSource is a simple xml file, looking something like this:

<?xml version='1.0' encoding='utf-8'?> <Database Name='MyDatabase' xmlns='http://schemas.microsoft.com/linqtosql/mapping/2007'>   <Table Name='dbo.MyFirstTable' Member='MyFirstTable'>     <Type Name='MyFirstTable'>       <Column Name='ID' Member='ID' Storage='_ID' DbType='UniqueIdentifier NOT NULL' IsPrimaryKey='true' IsDbGenerated='true' AutoSync='OnInsert' />       <Association Name='WaStaArtArtikel_WaVerPreisanfragen' Member='WaStaArtArtikel' Storage='_WaStaArtArtikel' ThisKey='ArtikelID' OtherKey='ID' IsForeignKey='true' />     </Type>   </Table>   <Table Name='dbo.MySecondTable' Member='MySecondTable'>     <Type Name='MySecondTable'>       <Column Name='ID' Member='ID' Storage='_ID' DbType='UniqueIdentifier NOT NULL' IsPrimaryKey='true' IsDbGenerated='true' AutoSync='OnInsert' />       <Column Name='FirstTableID' Member='FirstTableID' Storage='_FirstTableID' DbType='UniqueIdentifier NOT NULL' />       <Association Name='MySecondTable_MyFirstTable' Member='MyFirstTable' Storage='_MyFirstTable' ThisKey='FirstTableID' OtherKey='ID' IsForeignKey='true' />     </Type>   </Table> </Database> 

This should be possible to create using reflection, for example I can get the database name from a data context like this:

using System.Data.Linq.Mapping; using System.Xml.Linq;  XDocument mapWriter = new XDocument(); DatabaseAttribute[] catx = (DatabaseAttribute[])typeof(WcfInterface.WaDataClassesDataContext).GetCustomAttributes(typeof(DatabaseAttribute), false); XElement xDatabase = new XElement('Database'); xDatabase.Add(new XAttribute('Name', catx[0].Name)); mapWriter.Add(xDatabase); 

My problem: I can’t find good documentation of the mapping, so extracting the necessary information is quite error-prone – maybe someone can point me to good docs of the mapping, or, even better, to a code example how to create the mapping file?

  • 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. 2026-05-11T09:38:45+00:00Added an answer on May 11, 2026 at 9:38 am

    Have you considered using LINQ to Entities, the mapping formats for LINQ to Entities are documented.

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

Sidebar

Related Questions

This is a follow up question to that at Can I create a HTML
This is a follow up question to a previous question I asked about calculating
I have a follow-up question to this one . I created a new form,
This is a follow-on question from the one I asked here . Can constraints
I have a follow up question to this question . Is it possible to
This is a follow-up question to ASP.NET How to pass container value as javascript
I have a follow up question to this one . Now that I have
This is a follow-up question to this question I asked earlier. Btw thanks Neil
This is a follow-up question to 1832203. I'm making it a new question as
My question is sort of a follow on from this question below but I

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.