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 |