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

Commit f1fa681

Browse files
committed
Add IgnoreOnUpdate / IgnoreOnInsert attributes
1 parent cd3d619 commit f1fa681

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed
1.5 KB
Binary file not shown.

lib/pcl/ServiceStack.Interfaces.dll

1.5 KB
Binary file not shown.

lib/pcl/ServiceStack.Interfaces.xml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceStack.OrmLite/FieldDefinition.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,17 @@ public string GetQuotedValue(object fromInstance, IOrmLiteDialectProvider dialec
9696

9797
public bool IsRefType { get; set; }
9898

99-
public override string ToString()
100-
{
101-
return Name;
102-
}
99+
public bool IgnoreOnUpdate { get; set; }
103100

104-
public bool ShouldSkipInsert()
105-
{
106-
return AutoIncrement || IsComputed || IsRowVersion;
107-
}
101+
public bool IgnoreOnInsert { get; set; }
102+
103+
public override string ToString() => Name;
108104

109-
public bool ShouldSkipUpdate()
110-
{
111-
return IsComputed;
112-
}
105+
public bool ShouldSkipInsert() => IgnoreOnInsert || AutoIncrement || IsComputed || IsRowVersion;
113106

114-
public bool ShouldSkipDelete()
115-
{
116-
return IsComputed;
117-
}
107+
public bool ShouldSkipUpdate() => IgnoreOnUpdate || IsComputed;
108+
109+
public bool ShouldSkipDelete() => IsComputed;
118110

119111
public bool IsSelfRefField(FieldDefinition fieldDef)
120112
{

src/ServiceStack.OrmLite/OrmLiteConfigExtensions.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ internal static ModelDefinition GetModelDefinition(this Type modelType)
8787

8888
var sequenceAttr = propertyInfo.FirstAttribute<SequenceAttribute>();
8989
var computeAttr = propertyInfo.FirstAttribute<ComputeAttribute>();
90+
var computedAttr = propertyInfo.FirstAttribute<ComputedAttribute>();
9091
var customSelectAttr = propertyInfo.FirstAttribute<CustomSelectAttribute>();
9192
var decimalAttribute = propertyInfo.FirstAttribute<DecimalLengthAttribute>();
9293
var belongToAttribute = propertyInfo.FirstAttribute<BelongToAttribute>();
@@ -140,12 +141,14 @@ internal static ModelDefinition GetModelDefinition(this Type modelType)
140141
IsPrimaryKey = isPrimaryKey,
141142
AutoIncrement =
142143
isPrimaryKey &&
143-
propertyInfo.HasAttributeNamed(typeof(AutoIncrementAttribute).Name),
144+
propertyInfo.HasAttributeNamed(nameof(AutoIncrementAttribute)),
144145
IsIndexed = !isPrimaryKey && isIndex,
145146
IsUnique = isUnique,
146147
IsClustered = indexAttr != null && indexAttr.Clustered,
147148
IsNonClustered = indexAttr != null && indexAttr.NonClustered,
148149
IsRowVersion = isRowVersion,
150+
IgnoreOnInsert = propertyInfo.HasAttributeNamed(nameof(IgnoreOnInsertAttribute)),
151+
IgnoreOnUpdate = propertyInfo.HasAttributeNamed(nameof(IgnoreOnUpdateAttribute)),
149152
FieldLength = stringLengthAttr?.MaximumLength,
150153
DefaultValue = defaultValueAttr?.DefaultValue,
151154
CheckConstraint = chkConstraintAttr?.Constraint,
@@ -156,7 +159,7 @@ internal static ModelDefinition GetModelDefinition(this Type modelType)
156159
GetValueFn = propertyInfo.CreateGetter(),
157160
SetValueFn = propertyInfo.CreateSetter(),
158161
Sequence = sequenceAttr != null ? sequenceAttr.Name : string.Empty,
159-
IsComputed = computeAttr != null || customSelectAttr != null,
162+
IsComputed = computeAttr != null || computedAttr != null || customSelectAttr != null,
160163
ComputeExpression = computeAttr != null ? computeAttr.Expression : string.Empty,
161164
CustomSelect = customSelectAttr?.Sql,
162165
Scale = decimalAttribute?.Scale,
@@ -165,7 +168,7 @@ internal static ModelDefinition GetModelDefinition(this Type modelType)
165168
IsRefType = propertyType.IsRefType(),
166169
};
167170

168-
var isIgnored = propertyInfo.HasAttributeNamed(typeof(IgnoreAttribute).Name)
171+
var isIgnored = propertyInfo.HasAttributeNamed(nameof(IgnoreAttribute))
169172
|| fieldDefinition.IsReference;
170173
if (isIgnored)
171174
modelDef.IgnoredFieldDefinitions.Add(fieldDefinition);

0 commit comments

Comments
 (0)