Is it possible to use Linq to ALTER a database table?

旧时模样 提交于 2019-12-23 12:36:37

问题


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



来源:https://stackoverflow.com/questions/1337652/is-it-possible-to-use-linq-to-alter-a-database-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!