Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# LINQ Beginner Data Help
Hello,
 
I am trying to learn how LINQ to SQL works.
So far it seems like it's exactly what I need, but at work I do often have the following scenario:
 
The development PC has a default database with e.g. a table named "tTable1", Columns "Price" and "Customer".
The Customer PC has the same database but with e.g. a Table named "tTable1" (same name) and Columns "Price", "Customer" + "UserdefinedColumn1","UserdefinedColumn2".
 
To switch DataContext connection I think I will have to do something like this: http://steveclements.net/blog/Dynamic-connection-for-LINQ-to-SQL-DataContext[^]
 
But what about the Custom Fields in the Table, the class does not contain them as property? How can I "query" them?
 
Can I use LINQ to SQL in this scenario or do I need to use LINQ to Dataset so that I can read the custom Fields in a dataset?
 
Any suggestions or links welcome.
 
Thank you
Posted 16-Jan-13 8:33am
Belial092.6K
Edited 16-Jan-13 9:39am
v2
Comments
milenalukic at 20-Jan-13 19:41pm
   
Are these custom fields columns for which you do not know the names?
If so how do you query them at present?
Belial09 at 21-Jan-13 2:57am
   
Yes I know the names of the custom columns.
We build add-ons to an existing software which has a function to add userdefined columns to the default SQL tables.
 
For Example:
The user has products in the programm with 4 columns, the ones without „USER_“ are default columns of the table (known columns):
 
- Price (default)
- Productnumber (default)
- USER_EAN (userdefined)
- USER_Pictureurl (userdefined)
 
At the moment we give them properties where they can add the custom field names, so we can query them in an SQLDataReaderusing an SQL-Query string.
 
Summary:
- The tablename is known at design time
- The default table columns are known at design time
- The userdefined columns are only known at runtime

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
In this case I don't know of a way that Linq can help you.
 
You either need to stick to your current way or look into dynamic SQL.
 
To be honest it's more of a case that if it works don't fix it!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 235
1 DamithSL 225
2 OriginalGriff 198
3 George Jonsson 170
4 Maciej Los 165
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100