SQLQUERY on DBContext

Jan 26 2017 1:14 PM
Hello, I need help with this…..I'm Developing a web application with dbcontext
where I need to build a generic function that receive any entity and return data, for I to use after,
already I built a method for to use _entities.Database.ExecuteSqlCommand(Query), but it is only for Insert and Update, I need now créate afor SELECT to any table on my context, I saw examplos with SQLQUERY and IQueryable<T> but I dont understand those examples
 
I have a Proy with 
public abstract class GenericRepository<C, T> : IGenericRepository<T> where T : class where C : DbContext, new()
{
   public virtual void ExecuteSQLCommand(string consulta)
   {
      _entities.Database.ExecuteSqlCommand(consulta);
   }
 
 
Also I have an Interface
 public interface IGenericRepository<T> : IDisposable where T : class 
{
void ExecuteSQLCommand(string consulta);
}
 
 
 
and I have a Business Class with the method(Another proy, same solution)
public bool SQlComand(string Query, params string[] Parametros)
{
try
{
string strSqlQuery = string.Format(Query, Parametros);
unitOfWork.TablasTipo.ExecuteSQLCommand(strSqlQuery);
return true;
}
catch(Exception ex)
{
return false;
}
}
 
and in my code
string[] Parametros = new string[6];
Parametros[0] = "";
Parametros[1] = "'";
Parametros[2] = "'" ;
Parametros[3] = ""; 
Parametros[4] = "'";
Parametros[5] = "";
if (tablas.SQlComand("Insert into {0} Values({1},{2},{3},{4},{5})", Parametros)==true)
{
litMensaje.Text = WebFormUtilities.GenerarMensajeAlerta(WebFormUtilities.TipoAlertaMensaje.Success, "OK");
}
 
 
How to build a method in each proy and how in the last, I can receive the data????????????????
 
 
please help.... 

Answers (1)