Make a SQL query with Entity Framework 4

2

How do I perform a query on the database using Entity Framework 4 by passing a previously stored string within 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 it for lack of time.

This is the 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.

    
asked by anonymous 16.06.2014 / 20:48

1 answer

1

For Entity Framework command execution with query (which returns data), you need to have some data types defined for query result mapping.

If you want un-typed results, I suggest you use SqlConnection + DbCommand to run the query and parse the result via DbReader object.

Source: link

    
26.06.2014 / 23:05