使用Linq和Entity Framework更新列名称 [英] Update column name using Linq and Entity Framework

查看:149
本文介绍了使用Linq和Entity Framework更新列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新表中的列名.我知道sql查询

I want to update the column name in a table. i know sql query

sp_RENAME 'Table_First.Name', 'NameChange' , 'COLUMN'


但是我使用的是Entity Framework,所以我不知道如何在LINQ中编写查询.



but i am using Entity Framework, so i don''t know how to write query in LINQ.


Please help me!

推荐答案

您好,您必须使用ExecuteStoreCommand,以下是一个示例:

Hi, you have to use ExecuteStoreCommand, here is an exemple:

using(DatabaseContext db = new DatabaseContext())
{

db.ExecuteStoreCommand("ALTER TABLE [City] ALTER COLUMN [Id] IDENTITY (1,1)");

}



希望对您有帮助



Hope it helps


您无法使用Linq在EF中做到这一点.正如已经指出的,必须通过直接在连接上执行SQL来完成.

您自己创建的问题是EF将不再能够将实体映射到该表,因为yiu更改了架构.
You can''t do this in EF using Linq. It has to be done by executing SQL directly on the connection, as has already been pointed out.

The problem yourl''re creating for yourself is the EF will no longer be able to map entities to that table because yiu changed the schema.


这篇关于使用Linq和Entity Framework更新列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆