Justin C
Justin C

Reputation: 1924

need to remove a column from a table in a Linq project

I have extensive experience working in ASP.NET and Sql Server but I am new to Linq. I have just inherited a project that was created using Linq.

Unfortunately the last developer knew nothing of efficiency and was storing images in the database in a truly terrible way. I have modified the code so that it no longer uses the column that stored the image. Now I want to completely delete that column from the database to keep the Linq queries from wasting time and resources pulling in these huge files.

I searched my project for every reference to the column and removed it, then deleted the column from the database (don't worry, I have plenty of backups of everything). When I did this I began to get error messages about an invalid column name for the column I deleted.

So my question is, how the heck do you modify the structure of a table when using Linq?

Upvotes: 0

Views: 2040

Answers (3)

Eric Falsken
Eric Falsken

Reputation: 4932

If you removed the file from the dbml file, and it didn't pick up on the change, go ahead and right-click the dbml file and choose "Run Custom Tool". Note that if you look at the file's properties (right-click on the entry in solution explorer) you should see the custom tool listed as "MSLinqToSQLGenerator".

Worst case: If you expand the file, and look at the "dbmlfilename.designer.cs" file you should be able to find the field/column name in question. Go ahead and delete it from that file. (one property (with attribute and getter/setter) and one field with the same name (starting with an _ character).

It's the attribute on the property in the designer file that causes the runtime exception.

Upvotes: 0

Matthew Dresser
Matthew Dresser

Reputation: 11442

Just delete the table from the Linq-Sql designer, then add it again.

Upvotes: 1

David
David

Reputation: 12906

You need to be sure to remove the column from the DBML itself. Just view the DBML in the designer and delete the appropriate column. You would not get any error at compile time since it does not check to see if the DBML actually matches up with the database during compiliation.

Upvotes: 1

Related Questions