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