Click or drag to resize
SqlExpressionEGetUpdateSql Method
Creates a UPDATE SQL based on the passed parameters.

Namespace: LiteRepository
Assembly: LiteRepository (in LiteRepository.dll) Version: 2.0.4
Syntax
C#
public string GetUpdateSql(
	Type type = null,
	Expression<Func<E, bool>> where = null
)

Parameters

type (Optional)
Type: SystemType
Type that contains subset of E members. Used for generate fields list
where (Optional)
Type: System.Linq.ExpressionsExpressionFuncE, Boolean
Where expression. You can use members of E. Other values will be evaluated.

Return Value

Type: String
A string with a update query.
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 = GetUpdateSql();
// update User set FirstName = @FirstName, SecondName = @SecondName, Birthday = @Birthday where Id = @Id;

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

C#
var p = new { FirstName = "", SecondName = "" };
var sql = GetUpdateSql(type:p.GetType()); 
// update User set FirstName = @FirstName, SecondName = @SecondName where Id = @Id;

Where expression used like in GetSelectSql, but you can't pass parameters object.

See Also