Click or drag to resize
SqlExpressionEGetSelectByKeySql Method
Creates a SELECT SQL for single entity based on the passed parameters.

Namespace: LiteRepository
Assembly: LiteRepository (in LiteRepository.dll) Version: 2.0.4
Syntax
C#
public string GetSelectByKeySql(
	Type type = null
)

Parameters

type (Optional)
Type: SystemType
Type that contains subset of E members. Used for generate fields list.

Return Value

Type: String
A string with a select query (parameters are the same like Primary Key).
Examples

Suppose we have a class:

C#
public class User {
    [SqlKey]
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string SecondName { get; set; }
    public DateTime Birthday { get; set; }
    [SqlIgnore]
    public string FullName { get { return FirstName + " " + SecondName; } }
}

If you don't passed any parameter into method, it returns default update SQL:

C#
var sql = GetSelectByKeySql();
// select * from User where Id = @Id;

Passing type you sets subset of columns which you want to update:

C#
var p = new { FirstName = "", SecondName = "" };
var sql = GetSelectByKeySql(type:p.GetType()); 
// select FirstName, SecondName from User where Id = @Id;
See Also