Return the number of characters in a text field or in the text representation of a field.
public FunctionReference Length( )
Length
takes no parameters
Type: FunctionReference
A reference to a column being selected with a string length function applied to it
Exception | Condition |
---|---|
InvalidOperationException
|
Length has been used or daisychained to a base function (All, FindAllBy, …) rather than to a column in a Select clause.
|
NullReferenceException
|
Length has been daisychained to a table reference rather than a column reference within a Select clause.
|
ArgumentException |
You have passed one or more arguments to Length |
Note that issues #289 - #290 are still open with regards to exceptions thrown by Length.
Length
must be called only within a Select
clause, appended to one of the fields being selected.
Length
on a non-string field, the value returned is that of the string representation of that fieldLength
will not apply grouping to the query.To return the length of each title of the Albums in the Albums table, and reference it as TitleLength, use the following code:
var details = db.Albums.Select(db.Albums.Title.Length().As("TitleLength"));
Simple.Data sends the following SQL to the database when details is evaluated
select len([dbo].[Albums].[Title]) AS [NameLength] from [dbo].[Albums]