Validate if there is a record in a DB table and store in a variable

0

I am making a query to validate if there is a record in the database, for this I used the following

I declare variable

decimal serie= 10002;//este valor corresponde a un ejemplo, la variable puede tomar cualquier valor

I make the query

string sql2 = "SELECT codigo from tabla2 WHERE codigo=@serie";

My intention is to capture that value of the code field in the following variable

var camp = db.Database.SqlQuery<decimal>(sql2);

try it that way, that I have to modify so that I can capture that value in that variable

    
asked by Andrex_11 20.09.2018 в 15:53
source

1 answer

1

The problem I imagine is that SqlQuery normally returns a list, but in your case you only want one result. In that case, you must specify it. There are several ways to indicate that you only want one result:

answered by 20.09.2018 / 16:49
source