I know I could do something like this with SQLDataReader, but with EF?
EF/LINQ does not populate multiple separate objects. It will populate navigation properties though.
Just use ADO.NET since you already know how to handle this in ADO.NET.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
ASP.NET (NOT CORE) MVC
I need to execute ANY random query with any number of parameters, and return the results in a page.
so this might be a query...
select Firstname, lastName from customers where State=@state
or this...
select T.ID, T.Transactiondate, T.amount, C.FullName, C.City, C.State
from transactions T
join customers C on C.ID=T.CustomerID
where
T.transactionDate between @d1 and @d2
or this (multiple answers)
select * from customers;
select * from orders;
So the code I've seen so far won't compile, as this...
List<string> parms = Common.ExtractSQLParams(query.SQL);
List<object> paramset = new List<object>();
foreach (string parm in parms)
{
string paramname = string.Format("@{0}", parm);
string paramval = Request.Form[parm];
paramset.Add(new SqlParameter(paramname, (object)paramval));
}
DbSqlQuery qry = db.Database.SqlQuery(query.SQL, paramset.ToArray()); // ERROR HERE
gives
Error CS1503 Argument 1: cannot convert from 'string' to 'System.Type' Error CS1503 Argument 2: cannot convert from 'object[]' to 'string'
I know I could do something like this with SQLDataReader, but with EF? Can this be done?
I know I could do something like this with SQLDataReader, but with EF?
EF/LINQ does not populate multiple separate objects. It will populate navigation properties though.
Just use ADO.NET since you already know how to handle this in ADO.NET.
the goal of EF was to return strongly typed objects from queries. if you want dynamic query results use a DataTable or DataReader via adodb.