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 开发者_StackOverflowcolumn name for the column I deleted.
So my question is, how the heck do you modify the structure of a table when using Linq?
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.
Just delete the table from the Linq-Sql designer, then add it again.
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.
精彩评论