如何在LINQ中引用使用保留字命名的字段?



table: 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

编辑

dbml

  [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到SQL DBML映射,并将UserType.Type的映射从名为"Type"的列更改为名为"[Type]"的列。您可以在设计器中执行此操作,也可以手动执行。

您可以在代码中将其引用为UserType.@Type

最新更新