Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 9e6ef47

Browse files
committed
Skip Updates fields for Update queries and ignore RowVersion in updates
1 parent 43fb3d8 commit 9e6ef47

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/ServiceStack.OrmLite.SqlServer/SqlServerExpression.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ public override string ToUpdateStatement(T item, bool excludeDefaults = false)
1414

1515
foreach (var fieldDef in ModelDef.FieldDefinitions)
1616
{
17+
if (fieldDef.ShouldSkipUpdate()) continue;
18+
if (fieldDef.IsRowVersion) continue;
1719
if (UpdateFields.Count > 0 && !UpdateFields.Contains(fieldDef.Name) || fieldDef.AutoIncrement) continue; // added
20+
1821
var value = fieldDef.GetValue(item);
1922
if (excludeDefaults && (value == null || value.Equals(value.GetType().GetDefaultValue()))) continue; //GetDefaultValue?
2023

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public abstract partial class SqlExpression<T> : ISqlExpression
2424
IList<string> insertFields = new List<string>();
2525

2626
private string sep = string.Empty;
27-
private bool useFieldName = false;
27+
protected bool useFieldName = false;
2828
private ModelDefinition modelDef;
2929
public bool PrefixFieldWithTableName { get; set; }
3030
public bool WhereStatementWithoutWhereString { get; set; }
@@ -659,7 +659,10 @@ public virtual string ToUpdateStatement(T item, bool excludeDefaults = false)
659659

660660
foreach (var fieldDef in modelDef.FieldDefinitions)
661661
{
662+
if (fieldDef.ShouldSkipUpdate()) continue;
663+
if (fieldDef.IsRowVersion) continue;
662664
if (updateFields.Count > 0 && !updateFields.Contains(fieldDef.Name)) continue; // added
665+
663666
var value = fieldDef.GetValue(item);
664667
if (excludeDefaults && (value == null || value.Equals(value.GetType().GetDefaultValue()))) continue; //GetDefaultValue?
665668

src/ServiceStack.OrmLite/Expressions/WriteExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static int Update<T>(this IDbCommand dbCmd, object updateOnly, Expression
127127
{
128128
var fieldDef = fields.FirstOrDefault(x =>
129129
string.Equals(x.Name, setField.Name, StringComparison.OrdinalIgnoreCase));
130-
if (fieldDef == null) continue;
130+
if (fieldDef == null || fieldDef.ShouldSkipUpdate()) continue;
131131

132132
if (sql.Length > 0)
133133
sql.Append(", ");

0 commit comments

Comments
 (0)