TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Danilo Alarcopn Lopez
NA
31
2.6k
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....
Reply
Answers (
1
)
POCO Generator?
I am getting error the type or namespace(webgrid) could not