| SqlExpressionEGetUpdateSql Method |
Namespace: LiteRepository
public string GetUpdateSql( Type type = null, Expression<Func<E, bool>> where = null )
Suppose we have a class:
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:
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:
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.