kgst
kgst

Reputation: 243

Invalid column name 'level'

I am having trouble adding a column to my table, it seems simple so I don't understand why I am getting this error. To add the column in SQL I used the following Query:

ALTER TABLE [Trades]
ADD level nvarchar(max)

To add to the model I added:

    public string level { get; set; }

to public class trade.

What could the issue be?

edit: Here is the full error:

Invalid column name 'level'. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'level'.

Source Error: 
Line 20:         {
Line 21:             ViewBag.Name = Name;
Line 22:             return View(db.Movies.ToList());
Line 23:         }
Line 24: 

Upvotes: 0

Views: 1701

Answers (1)

Eoin Campbell
Eoin Campbell

Reputation: 44268

If this is a SQL Server Instance, Level is a reserved keyword. (Used when changing the TRANSACTION ISOLATION for example.

Try change the property name to something else, or add a ColumnName attribute to the property, to map it to a different SQL Column.

e.g. Create a column on your table with

ALTER TABLE [Trades]
ADD LevelProperty nvarchar(max)

and use the following decorator on your EF POCO

[Column("LevelProperty")]
public string Level { get; set; }

Upvotes: 0

Related Questions