如何引用 LINQ 中使用保留字命名的字段?
表:UserTypes
字段:行、名称、类型
此代码不起作用:
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
);
我收到此错误:
键入的单词是保留单词。我无法使用该单词
类型
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;
}
}
}
}
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 word
Type
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;
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
进入 LINQ to SQL DBML 映射并将
UserType.Type
的映射从名为“Type”的列更改为名为“[Type]”的列。您可以在设计器中或手动执行此操作。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.您可以在代码中将其引用为
UserType.@Type
。You can reference it as
UserType.@Type
in your code.