Szq. orm. SQL detailed instructions, szq. orm. SQL

Source: Internet
Author: User

Szq. orm. SQL detailed instructions, szq. orm. SQL

Var connStr = ConfigurationManager. ConnectionStrings ["dbconnstr"]. ConnectionString;

SQLContext db = new SQLContext (connStr );
// List Query
Var list1 = db. GetList <Config> (s => s. ID> 5 );
Var list2 = db. GetList <Config> ("select * from Config where id> @ id", null, new SqlParameter ("@ id", 5 ));
Var list3 = db. Query <Config> (). Where (s => s. ID> 5). ToList ();


// Multi-condition Query
Var query = db. Query <Config> ();
Query. Where (s => s. Name = "B ");
Query. Where (s => s. ID> 5 );
Var result = query. ToList ();


// Query by PAGE
Var pageResult1 = db. GetPageResult <Config> (new SQL. PageHelper. PageBase {PageIndex = 0, PageSize = 10}, s => s. ID, true );
Var pageResult2 = db. GetPageResult <Config> (new SQL. PageHelper. PageBase {PageIndex = 0, PageSize = 10}, "select * from Config", "Id asc ");
Var pageResult3 = db. Query <Config> (). ToPageResult (new SQL. PageHelper. PageBase {PageIndex = 0, PageSize = 10}, s => s. ID, true );


// Insert
Int row1 = db. Insert <Config> (new Config {Name = ""});
Int row2 = db. InsertBatch <Config> (new List <Config> {
New Config {Name = "B "},
New Config {Name = "c "}
});


// Update
Int update1 = db. Update <Config> (new Config {ID = 10033, Name = "aa "});
Int update2 = db. query <Config> (). set (s => s. name, "aaa "). where (s => s. ID = 10033 ). update ();


// Delete
Int delete1 = db. Delete <Config> (s => s. ID = 10033 );
Int delete2 = db. Query <Config> (). Where (s => s. ID = 10033). Delete ();

Int delete3 = db. Delete <Config> (new Config {ID = 10035 });

 

// If the preceding statements are not supported, download the latest version.

: Http://files.cnblogs.com/files/wuyifeixiang/orm.rar

 

Related Article

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.