Search code examples
c#entity-framework-5

Using numbers at the beginning of variable name


I'm mapping up data from an SQL database into an object in c#. The problem is, one of the columns is unfortunately named "100_hrs". So when I am making my C# object, I get an error in the declaration:

public float 100_hrs {get; set;}

I've tried using @ in front but it does not work. If the property is not named the same as the table column, then it does not map up. How can I map this up?


Solution

  • Answering why the @ didn't work.

    @ lets you declare variables with keywords names, it doesn't allow you to use invalid tokens.

    MSDN

    Regarding to the main question, it seems like you should change the table column name.
    If you're using some sort of mapping engine like NHibernate of EntityFramework, you can change the mapping file. Example:

    [Column("100_hrs")]
    public float hrs100 {get; set;}