Csharp:dapper Sample

Source: Internet
Author: User
<span id="Label3"></p><p><p>You can find Dapper on Google Code here:http://code.google.com/p/dapper-dot-net/and the GitHub distro here:https://gith Ub.com/samsaffron/dapper-dot-net.</p></p><pre class="brush:csharp;gutter:true;"> <summary>///additional Records///</summary>///<param name= "bookplacelistinfo" >< /param>///<returns></returns> public int insertbookplacelist (bookplacelistinfo bookPlaceList ) {int ret = 0; Try {list<bookplacelistinfo> list=new list<bookplacelistinfo> (); List. ADD (bookplacelist); StringBuilder str = new StringBuilder (); Str. Append ("INSERT into bookplacelist"); Str. Append ("([bookplacename], [bookplacecode], [bookplaceparent]) VALUES"); Str. Append ("(@BookPlaceName, @BookPlaceCode, @BookPlaceParent)"); Ret=sqlmapperutil.insertmultiple<bookplacelistinfo> (str. ToString (), list, sqlhelper.connectionstring); } catch (SqlException Ex) {throw ex; } return ret; }//<summary> Append multiple Records//</summary>//<param name= "bookplacelist" ></param>//<r eturns></returns> public int Insertbookplacelistmore (list<bookplacelistinfo> BookPlaceList) { int ret = 0; Try {StringBuilder str = new StringBuilder (); Str. Append ("INSERT into bookplacelist"); Str. Append ("([bookplacename], [bookplacecode], bookplaceparent]) VALUES"); Str. Append ("(@BookPlaceName, @BookPlaceCode, @BookPlaceParent)"); ret = sqlmapperutil.insertmultiple<bookplacelistinfo> (str. ToString (), bookplacelist, sqlhelper.connectionstring); } catch (SqlException Ex) {throw ex; } return ret; }///<summary>//modify Record///</summary>///<param name= "bookplacelistinfo" >< /param>///<returns></returns> public int updatebookplacelist (bookplacelistinfo Bookplacelist) {int ret = 0; Try {list<bookplacelistinfo> List = new List<bookplacelistinfo> (); List. ADD (bookplacelist); StringBuilder str = new StringBuilder (); Str. Append ("UPDATE bookplacelist SET"); Str. Append ("[bookplacename][email protected],"); Str. Append ("[bookplacecode][email protected],"); Str. Append ("[bookplaceparent][email protected]"); Str. Append ("where"); Str. Append ("[bookplaceid][email protected]"); ret = sqlmapperutil.insertmultiple<bookplacelistinfo> (str. ToString (), list, sqlhelper.connectionstring); } catch (SqlException Ex) {throw ex; } return ret; }///<summary>/Delete Records///</summary>///<param name= "bookplaceidinfo" ></param>///<returns>& lt;/returns> public bool Deletebookplacelist (int bookplaceid) {bool ret = false; Try {int temp = 0; StringBuilder str = new StringBuilder (); Str. Append ("deletebookplacelist WHERE Bookplaceid = @BookPlaceID"); temp = Sqlmapperutil.insertupdateordeletesql (str. ToString (), New {bookplaceid = bookplaceid}, sqlhelper.connectionstring); If (temp! = 0) {ret = true; }} catch (SqlException Ex) {throw ex; } return ret; }///<summary>///query Record///</summary>///<param name= "bookplaceidinfo" ></ Param>///<returns></returns> Public BookPlacelistinfo selectbookplacelist (int bookplaceid) {bookplacelistinfo bookplacelist = null; Try {StringBuilder str = new StringBuilder (); Str. Append ("select * from bookplacelist WHERE Bookplaceid = @BookPlaceID"); Bookplacelist = sqlmapperutil.sqlwithparamssingle<bookplacelistinfo> (str. ToString (), New {bookplaceid = bookplaceid}, sqlhelper.connectionstring); } catch (SqlException Ex) {throw ex; } return bookplacelist; }///<summary>///query All records///</summary>///<returns></returns> Public list<bookplacelistinfo> selectbookplacelistall () {list<bookplacelistinfo> List = new List<bookplacelistinfo> (); Try {string str = "select * from bookplacelist"; List = Sqlmapperutil.sqlwithparams<bookplacelistinfo> (str, null, sqlhelper.connectionstring); } catch (SqlException Ex) {throw ex; } return list; }</pre><p><p>Nearly half as much as sqlhelper than bulk data insertion</p></p><p><p>Csharp:dapper Sample</p></p></span>

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.