The problem of returning data by Dapper Querymultiple = = "Dapper querymultiple does not help us to identify the order of multiple return values

Source: Internet
Author: User

Today help a group of friends to tidy up Dapper basic tutorial when hands and feet quickly point, and then encountered a small problem, Dapper querymultiple return data problems

Multiple return values with Querymultiple, which everyone knows, if not clearly read the following document:

This is the official document:

Multiple Results

Dapper allows you to process multiple result grids in a single query.

Example:

var sql = @"select * from Customers where CustomerId = @idselect * from Orders where CustomerId = @idSelec T * from Returns where CustomerId = @id";      

According to the document, why is there no data, the ID has value? Can a multi-table only pass one parameter, and must have a relationship??? NoNoNo, if so many restrictions are called dapper??

Give you 3s to find the wrong .....

In fact, the order is reversed, the park friends can be a experience = = "Dapper querymultiple will not help us to identify the order of multiple return values

Read must be in the order in which the tables are returned (ARTICLE,QQMODEL,SEOTKD)

var articlelist = multi. Read<temp> ();//class is not necessarily the same as the table name
var qqmodellist = multi. Read<qqmodel> ();
var seotkdlist = multi. Read<seotkd> ();

The official documents are written in this way, so can we play something else? Do you have to define a class to get the corresponding strong type? Multiple return values can not be dynamically obtained??? NoNoNo

Direct

if (!multi. isconsumed)
{

var articlelist = multi. Read ();
var qqmodellist = multi. Read ();
var seotkdlist = multi. Read ();

}

The same effect

Sunday there will be an article in detail dapper, now to save .... Immediately, immediately.

Appendix:

            using (SqlConnection conn = new SqlConnection (connstr)) {string sqlstr = @ "Select I                                   D,title,author from article where Id = @Id select * from Qqmodel where Name = @Name                SELECT * from SEOTKD where Status = @Status "; Conn.                Open (); using (var multi = conn. Querymultiple (Sqlstr, new {Id = one, Name = "Hit Code", Status =)) {//multi. Isconsumed reader State, True is already released if (!multi. isconsumed) {////Strong type////Note that when read gets it must be in the order in which the tables are returned ( ARTICLE,QQMODEL,SEOTKD)//var articlelist = multi. Read<temp> ();//class is not necessarily the same as the table name//var qqmodellist = multi.                        Read<qqmodel> (); var seotkdlist = multi.                        Read<seotkd> (); Dynamic type var articleList = multi.                        Read (); var qqmodellist = multi.                        Read (); var seotkdlist = multi.                        Read (); #region Output foreach (var item in qqmodellist) {Co Nsole. WriteLine (item. Id + "" + Item. Name + "" + Item.                        Count); } foreach (var item in seotkdlist) {Console.writ Eline (item. Id + "|" + Item.                        Seokeywords); } foreach (var item in articlelist) {Console.wri Teline (item.                        Author); } #endregion}}}

  

The problem of returning data by Dapper Querymultiple = = "Dapper querymultiple does not help us to identify the order of multiple return values

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.