c# - How to get scalar value from a SQL statement in a .Net core application? -
the following code in .net core console application (ef core 2.0/sql server).
var sql = _context.set<string>() .fromsql("select dbo.functionreturnvarchar({0});", id);
got following exception?
cannot create dbset 'string' because type not included in model context.
is way without defining class property of string?
.set<tentity>()
entities backed context.
you can try workaround
dbcommand cmd = _context.database.getdbconnection().createcommand(); cmd.commandtext = "select dbo.functionreturnvarchar(@id)"; cmd.parameters.add(new sqlparameter("@id", sqldbtype.varchar) { value = id }); var value = (string) await cmd.executescalarasync();
Comments
Post a Comment