2
How do I perform a query in the database using Entity Framework 4 passing a string previously stored inside a StringBuilder
.
The reason is that the SQL query string is giant. I know it is not a good practice, but for now I will have to do so for lack of time.
That’s the string SQL of the query:
StringBuilder strSql = new StringBuilder();
strSql.AppendLine(string.Format("SELECT * FROM (SELECT TOP intRestante * FROM (SELECT TOP {0}", intTop))[... Continua, a string é gigante];
In Webforms I would do something like this:
objCommand = new SqlCommand();
objCommand.Connection = conn;
objCommand.CommandTimeout = 600;
objCommand.CommandText = strSql.ToString();
objCommand.Parameters.Add("@Parametros", SqlDbType.NVarChar, 100).Value = "%" + strParametros + "%";
SqlDataAdapter adp = new SqlDataAdapter(objCommand);
adp.Fill(dt);
I would like to know how to do exactly the same thing, but in Entity Framework.
Put the example and a snippet of code that can help solve your problem!
– user6026
If the
string
is very large, the correct is to fragment the single query into several queries.– Leonel Sanches da Silva
Gypsy Morrison Mendez I could do so, but the string is already ready and "want" me to use it.
– Junior Dias
@Good Juniordias, then put the
string
all here. I can do it, but it’s too bad to use it this way.– Leonel Sanches da Silva
@Ciganomorrisonmendez I already got it here, I used ctx.Database.Executesqlcommand Thank you very much!
– Junior Dias