Database component Hxj.data (16) (Field of query)

Source: Internet
Author: User

When the query field is not set in the query, the component defaults to return all field information, that is, select * FROM table

How do you set the field information that needs to be returned in the query?

The example in the previous section already exists to set the query field, which is set by the Select method.

The first example:

DbSession.Default.From<Products>()
         .Select(Products._.ProductID, Products._.ProductName)
         .ToDataTable();

Here is the set query to return only ProductID and ProductName two fields.

Generated sql:

Text:
SELECT [Products].[ProductID],[Products].[ProductName] FROM [Products]

Sometimes we need to set the alias for this field, such as select ProductName as PName from

The settings for aliases are also very simple.

DbSession.Default.From<Products>()
         .Select(Products._.ProductID, Products._.ProductName.As("pname"))
         .ToDataTable();

Set by the As method of the field.

Generated SQL

Text:
SELECT [Products].[ProductID],[Products].[ProductName] AS [pname] FROM [Products]

is not very simple AH.

Actually products._. ProductID is a field class that represents field information.

Field also provides some simple helper methods.

method sql
field.count () count record number
field.sum () sum Total /td>
field.avg () avg Ping  Mean value
field.len () len Length
field.trim ()
field.max ()
field.min ()
field.left (int length) start on the left to intercept the corresponding length content
field.right (int length)
field.substring (int startIndex, int endindex) intercept the corresponding range of field contents

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.