Reputation:
i want to get max code(my means last id of columns) with sql query
Thats my code :
var qre = dbms.Database.SqlQuery<TCOD_BANKS>("SELECT MAX(CODE) FROM TCOD_BANKS");
var data_main11 = qre.ToList();
foreach (var x1 in qre)
{
var aasd = x1.CODE;
}
When i start my code I see this error
System.Data.Entity.Core.EntityCommandExecutionException: 'The data reader is incompatible with the specified 'DENAF1399Model.TCOD_BANKS'. A member of the type, 'CODE', does not have a corresponding column in the data reader with the same name.'
my table is : TCOD_BANKS my column id is : CODE as int
please help me
Upvotes: 0
Views: 62
Reputation: 759
The query SELECT MAX(CODE) FROM TCOD_BANKS
will return a single number, so you can't try to read a result set with items of type TCOD_BANKS
. Try reading a single number from the result like this:
var qre = dbms.Database.SqlQuery<int>("SELECT MAX(CODE) FROM TCOD_BANKS").First();
Upvotes: 1