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?
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.
To escape reserved keywords in DDL statements, enclose them in backticks (`). To escape reserved keywords in SQL SELECT statements and in queries on views, enclose them in double quotes ('').
Both these are keywords in SQL. The trick here is to type the column names inside the square brackets '[]' so that they are not read as a Reserved Word by the compiler.
If the table names and the column names are shown in lowercase letters this means they are delimited and quotation marks need to be used for the table names and the column names when executing SQL queries against the Oracle database.
Precede the identifier with a "@":
@void
Is the name of an identifier "void", not the keyword (this works anywhere an identifier is needed).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With