Question

Hello all i have a small issue with Linqpad with a poorly setup Database

Firstly i have a database where the creator has tables with column named the same as table which he is using as an enabled field.

In Addition to this these tables have the columns Content and Value.

After experimenting with this if the table has a column named the same as the Table it renames the column to Content and then Value if it has a column name similarly named.

if i then try to query (below) i loose the column with the same column name as the table. Does anyone know of any method to get around this. as it makes linqpad use impossible as this is prominent over all the database tables i am currently using?

Example below

If i have

TestTable Layout

   CREATE TABLE [dbo].[TestTable](
    [TestTableID] [int] NOT NULL,
    [TestTable] [varchar](max) NULL,
    [Content] [varchar](max) NULL,
    [Value] [varchar](max) NULL
) 

enter image description here

As you can see im missing the

Was it helpful?

Solution 2

This got me going for the better part of an hour now, but I think I found a working solution for you.

the problem is the Linq-To-Sql provider in Linqpad itself. If you open up Visual Studio and create a context class based on your database, you will notice the column TestTable gets renamed to TestTable1.

So what I have done to take advantage of this, is created a new project of type "class library" - target Framework 4.0.

  1. In this I added a new Linq-to-Sql class and dragged the TestTable into it. enter image description here

  2. Go into your class1.cs and insert: (I don't know if this is neccessary)

    //I named my context L2S. Replace accordingly

    public L2SDataContext context = new L2SDataContext();

  3. Compile

  4. Add a new connection to Linqpad using a typed context! enter image description here

  5. Connect to your server

  6. Query! the result

OTHER TIPS

What happens is that if your table "foo" contains a field named "foo", then this field gets renamed to "content" in linqpad.

In your case, the field "content" already exists, so you end up with only one of the two created in the context's table (thus the "missing" field).

As a workaround, you can try to avoid the collision by changing the names (table name, field name, content field name), or creating a view with aliased names to avoid collisions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top