LINQ to SQL列有关键字作为列名,如何引用/转义

时间:2022-09-22 20:50:29

In a LINQ to SQL statement I've got a column name in the database that's also a C# keyword (void). How do I get the compiler to treat this as an object property and not the keyword?

在LINQ to SQL语句中,我在数据库中有一个列名,它也是一个C#关键字(void)。如何让编译器将其视为对象属性而不是关键字?

I could re-write this in with the method notation, sure, but there's got to be a way to give the compiler a hint here...

我可以使用方法表示法重写这个,当然,但是必须有一种方法可以在这里给编译器一个提示......

var p = from c in mytable
        where c.id = rowNumber
        select ( new { voidedState = c.void } );  // <--- Problem is here

The error is:

错误是:

Identifier expected; 'void' is a keyword

I can't argue with that, I'm just looking for a workaround.

我不能争辩,我只是在找一个解决方法。

Thanks.

1 个解决方案

#1


Precede the identifier with a "@":

在标识符前面加上“@”:

@void

Is the name of an identifier "void", not the keyword (this works anywhere an identifier is needed).

标识符的名称是“void”,而不是关键字(这适用于需要标识符的任何地方)。

#1


Precede the identifier with a "@":

在标识符前面加上“@”:

@void

Is the name of an identifier "void", not the keyword (this works anywhere an identifier is needed).

标识符的名称是“void”,而不是关键字(这适用于需要标识符的任何地方)。