Microorm. Net (4) Table. Query ()-Where

Source: Internet
Author: User

Microorm. Net homepage:

Http://code.google.com/p/micro-orm-net/

Overview of the microorm. Net series directories:

Http://www.cnblogs.com/mapserver/archive/2012/04/07/2436129.html

 

This article demonstrates the query of microorm. net. Please refer to the table. Query () API documentation:

// ---------------------- Part 1 ---------------------- query where (expression criteria) query select (Params mathe [] maths) query select (Params column [] columns) query join (Table jointable, expression on) query innerjoin (Table jointable, expression on) query leftjoin (Table jointable, expression on) query leftouterjoin (Table jointable, expression on) query rightjoin (Table jointable, expression on) query rightouterjoin (Table jointable, expression on) query orderby (Params column [] columns) query orderbyasc (Params column [] columnsquery orderbydesc (Params column [] columns) query groupby (Params column [] columns) query having (expression criteria) query SKIP (INT skip) query take (INT take) query distinct () // ---------------------- Part 2 ---------------------- dynamic first () t first <t> () Dynamic last () t last <t> () ilist tolist () Dynamic [] toarray () ilist <t> tolist <t> () T [] toarray <t> ()

The preceding API is divided into two parts. The first part returns the query object, and the second part executes the SQL statement to the database to return the query result.

 

Where:

db.OrderDatail.Query()        .Where(db.OrderDetail.OrderId == "001")        db.OrderDatail.Query()        .Where(db.OrderDetail.OrderId == "001" && db.OrderDetail.Qty > 0)        db.OrderDatail.Query()        .Where(db.OrderDetail.OrderId == "001" && (db.OrderDetail.Qty > 0 || db.OrderDetail.OrderDetailId == "001")

 

Microorm. Net also supports table aliases. Even if the table alias is defined, the table alias can be used or not used in the where method expression.

The where method can be executed multiple times.

db.OrderDatail.As("od").Query() //table alias        .Where(db.od.OrderId == "001")        .Where(db.OrderDetail.Qty > 0)

 

The expressions of the where method also support like, isnull, and isnotnull.

db.OrderDatail.As("od").Query()        .Where(db.od.ProductId.IsNotNull())        .Where(db.od.ProductId.Like("CA%") 

 

The following shows how to execute an SQL statement to a database:

var od = db.OrderDetail.Query()                .Where(db.OrderDetail.OrderId == "001")                .First();

The generated SQL statement is as follows:

exec sp_executesql N'SELECT TOP 1 [_#0_].* FROM [dbo].[OrderDetail] [_#0_] WHERE [_#0_].[OrderId] = @p0 ',N'@p0 nvarchar(3)',@p0=N'001'

 

More:

var od1 = db.OrderDetail.Query()    .Where(db.OrderDetail.OrderId == "001")    .First<OrderDetail>();var od2 = db.OrderDetail.Query()    .Where(db.OrderDetail.OrderId == "001")    .Last();OrderDetail od3 = db.OrderDetail.Query()    .Where(db.OrderDetail.OrderId == "001")    .Last<OrderDetail>();IList ods1 = db.OrderDetail.Query()        .Where(db.OrderDetail.OrderId == "001")        .ToList(); dynamic[] ods2 = db.OrderDetail.Query()        .Where(db.OrderDetail.OrderId == "001")        .ToArray();IList<OrderDetail> ods3 = db.OrderDetail.Query()        .Where(db.OrderDetail.OrderId == "001")        .ToList<OrderDetail>();OrderDetail[] ods4 = db.OrderDetail.Query()        .Where(db.OrderDetail.OrderId == "001")        .ToArray<OrderDetail>(); 

 

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.