Friday, April 29, 2011

LINQ to SQL column has keyword as column name, how to quote/escape

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.

From stackoverflow
  • Precede the identifier with a "@":

    @void
    

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

    clintp : I've been looking all over for this. Thanks.

0 comments:

Post a Comment