开发者

How do I reference a field in LINQ that is named using a reserved word?

table:UserTypes

Fields:row,name,Type

This code is not working:

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

But, this code does...

dc.ExecuteQuery<UserType >("update dbo.UserType set Type='personalPage' where row={0}",user.Row );

I get this error:

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

EDIT

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
     {
 开发者_JS百科   get
    {
        return this._Type;
    }
    set
    {
        if ((this._Type != value))
        {
            this._Type = value;
        }
    }
    }

}               


Go into your LINQ to SQL DBML mapping and change the mapping for UserType.Type from being to a column named "Type" to a column named "[Type]". You can do this in the designer, or manually.


You can reference it as UserType.@Type in your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜