Avatar of kingy0489
kingy0489
 asked on

Creating LINQ datacontext when tables are unknown

Hello,

I am working with a very old database (unchangeable) which is not normalised very well. Because of this, the software we use must add and remove tables from time to time.

There is one table which keeps track of which other tables exist (I know, not pretty but thats what I have to work with).

How can I create a DataContext properly when I cannot know beforehand which tables exist? Can the mapping to objects be done programmatic-ally at runtime?

Ak
.NET ProgrammingC#

Avatar of undefined
Last Comment
kingy0489

8/22/2022 - Mon
Fernando Soto

Hi kingy0489;

You say that, "I am working with a very old database", unless the server you are using is not Microsoft SQL Server you can't use Linq to SQL because it only supports MS SQL Server currently. The Linq to Entity implementation supports multiple types of database servers as long as there is an implementation for it. Either of the two implementations requires you to know at design time the database information such as tables names and columns and so on. So in answer to your question, no, you need the information in order to build a strongly typed model to program with.

Fernando
kingy0489

ASKER
Sorry, the database is 5 years old, so not massively old, running on SQL Server 2005, it predates my time at this company and I am told it needs to remain as is for legacy reasons.

Would you suggest I use LINQ for the tables I do know of, and come up with something else for the other tables?
ASKER CERTIFIED SOLUTION
tovvenki

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
kingy0489

ASKER
Not exactly what I was hoping for, but still the best answer!

Thanks.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes