Pass the time parameter by SqlParameter, the code is as follows:
var param = new List<SqlParameter>(); Param. ADD (New SqlParameter ("@StartTime", DateTime.Parse (req. (StartTime))); Param. ADD (New SqlParameter ("@EndTime", DateTime.Parse (req. (EndTime))); Response. List = _ctx. Database.sqlquery<Receivesummeryitem>(sql, param. ToList ()). ToList ();
The results have been error
Does not exist from object type System.Collections.Generic.List ' 1[[system.data.sqlclient.sqlparameter, System.Data, version=4.0.0.0, Culture=neutral, publickeytoken=b77a5c561934e089]] to a known managed provider native type mapping.
English error
No mapping exists from Object type System.Collections.Generic.List ' 1[[system.data.sqlclient.sqlparameter, System.Data , version=4.0.0.0, Culture=neutral, publickeytoken=b77a5c561934e089]] to a known managed provider native type.
by searching
https://stackoverflow.com/questions/9149919/ No-mapping-exists-from-object-type-system-collections-generic-list-when-executin
See the back of the ToList () changed to ToArray ()
var param = new List<SqlParameter>(); Param. ADD (New SqlParameter ("@StartTime", DateTime.Parse (req. (StartTime))); Param. ADD (New SqlParameter ("@EndTime", DateTime.Parse (req. (EndTime))); Response. List = _ctx. Database.sqlquery<Receivesummeryitem>param. ToArray ()). ToList (); Response. TotalCount = Response. List.count ();
The results are good, it's amazing!
Get!
The EF framework uses the params parameter to pass values to prevent SQL injection error handling