Is it possible to use Linq to ALTER a database tab

2019-06-25 06:50发布

问题:

I am trying to programmatically drop a column in a table inside of an access database and found myself unable to do so! Is it at all possible? it makes me think that i don't have any clear idea of things linq to sql can't do. Any ideas?

回答1:

There's nothing in LINQ to SQL that allows you to do that without writing T-SQL, no.

Similarly, you can't do straight updates or deletes without selecting the data you want to alter first and manipulating the objects. You'd have to write stored procedures for those things and add them to your model to be called. See this MSDN page for an overview.

Using DataContext.ExecuteQuery should also work if you don't mind T-SQL in your source code.



回答2:

You can do it. Here's an example:

ALTER TABLE Import
Alter column [Tot_Val]  DECIMAL(10,2) ;

GO