The EF framework uses the params parameter to pass values to prevent SQL injection error handling

Source: Internet
Author: User
Tags sql injection

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.