Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
     {
    get
    {
        return this._Type;
    }
    set
    {
        if ((this._Type != value))
        {
            this._Type = value;
        }
    }
    }

}               
like image 603
ashkufaraz Avatar asked Aug 22 '11 20:08

ashkufaraz


2 Answers

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.

like image 141
jason Avatar answered Sep 22 '22 00:09

jason


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

like image 27
YoGoodDay Avatar answered Sep 21 '22 00:09

YoGoodDay