with a simplyfied query like that
$"SELECT 1 FROM T1 INNER JOIN T2 ON t2.x = t1.x";
how can i return the number with entity framework?
return await _context
.Set<XXX>()
.FromSqlRaw(query);
i know that using a .Set is mandatory but cannot use primitive type.
using a mapped type has no logic since i will need to return all columns
i want to avoid ado or mapper
even creating a poco class with a int property seems silly to mee
are there a good solution for it?
i also have many other cases with query that return true or false and need to use a common solution
thanks
EDIT
now i have ado solution:
var comando = _context.Database.GetDbConnection().CreateCommand();
await _context.Database.OpenConnectionAsync();
try
{
comando.CommandType = CommandType.Text;
comando.CommandText = $"SELECT 1 FROM TABLE WHERE SAMPLING_NAME = :NomeCampione AND USERID = :UserId";
comando.Parameters.Add(new OracleParameter("NomeCampione", NomeCampione));
comando.Parameters.Add(new OracleParameter("UserId", UserId));
return (int)((await comando.ExecuteScalarAsync()) ?? 0) == 1;
}
finally
{
if (_context.Database.GetDbConnection() != null && _context.Database.GetDbConnection().State == ConnectionState.Open)
_context.Database.CloseConnection();
}
but onestly i'am trying to avoid it