c# - 如何引用 LINQ 中使用保留字命名的字段?

标签 c# asp.net sql-server linq linq-to-sql

表:UserTypes

字段:row,name,Type

此代码无效:

 Int64 row = 1;
var myType = (from b in dc.UserTypes where b.Row == user.Row  select b).Single();
myType.Type = "personalPage";
dc.SubmitChanges();

但是,这段代码确实...
dc.ExecuteQuery<UserType >("update dbo.UserType set Type='personalPage' where row={0}",user.Row );

我收到这个错误:

Type the word is a word reserved.i can not user wordType

编辑

数据库管理

  [Table(Name="dbo.UserType")]
  public partial class UserType
 {

     private long _Row;

     private string _Type;

     public UserType()
     {
     }

     [Column(Storage="_Row", DbType="BigInt NOT NULL")]
     public long Row
     {
     get
      {
        return this._Row;
       }
     set
       {
        if ((this._Row != value))
        {
            this._Row = value;
        }
        }
    }

    [Column(Storage="_Type", DbType="NVarChar(500) NOT NULL", CanBeNull=false)]
    public string Type
     {
    get
    {
        return this._Type;
    }
    set
    {
        if ((this._Type != value))
        {
            this._Type = value;
        }
    }
    }

}               

最佳答案

进入您的 LINQ to SQL DBML 映射并将 UserType.Type 的映射从名为“Type”的列更改为名为“[Type]”的列。您可以在设计器中或手动执行此操作。

关于c# - 如何引用 LINQ 中使用保留字命名的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7153460/

相关文章:

c# - 为什么某些 Azure App Insight 指标没有出现在门户中?

c# - 调试 `WCF Service Library` 时我可以在哪里设置 try-catch block (即入口点/Main()-方法在哪里)

asp.net - MVC 应用程序中永远不会调用 GetClientValidationRules

SQL Server - 加入 4 个快速查询给我一个慢速查询

SQL 服务器计数

asp.net - 本地主机找不到存储过程 'dbo.aspnet_CheckSchemaVersion'

c# - 在 C# 中创建列表列表

c# - .NET 中 ActiveX 的替代品

asp.net - ASP 存储过程到 GridView

c# - 在网格顶部添加新行