|
@@ -422,10 +422,13 @@ namespace InABox.Database
|
|
|
var prefix = autoinc.AutoIncrementPrefix() ?? "";
|
|
|
|
|
|
var prop = CoreUtils.GetPropertyFromExpression<T, string>(autoinc.AutoIncrementField());
|
|
|
- var bRequired = false;
|
|
|
- foreach (var entity in entities)
|
|
|
- bRequired = bRequired || string.IsNullOrWhiteSpace(prop.GetValue(entity) as string);
|
|
|
- if (bRequired)
|
|
|
+
|
|
|
+ var requiredEntities = entities.Where(x =>
|
|
|
+ {
|
|
|
+ return (prop.GetValue(x) as string).IsNullOrWhiteSpace() && (x.ID == Guid.Empty || x.HasOriginalValue(prop.Name));
|
|
|
+ }).ToList();
|
|
|
+
|
|
|
+ if (requiredEntities.Count > 0)
|
|
|
{
|
|
|
|
|
|
var filter = new Filter<T>(prop.Name).IsGreaterThanOrEqualTo(String.Format("{0}0",prefix))
|
|
@@ -451,12 +454,11 @@ namespace InABox.Database
|
|
|
int.TryParse(id, out newvalue);
|
|
|
}
|
|
|
|
|
|
- foreach (var entity in entities)
|
|
|
- if (string.IsNullOrWhiteSpace(prop.GetValue(entity) as string))
|
|
|
- {
|
|
|
- newvalue++;
|
|
|
- prop.SetValue(entity, prefix + string.Format(autoinc.AutoIncrementFormat(), newvalue));
|
|
|
- }
|
|
|
+ foreach (var entity in requiredEntities)
|
|
|
+ {
|
|
|
+ newvalue++;
|
|
|
+ prop.SetValue(entity, prefix + string.Format(autoinc.AutoIncrementFormat(), newvalue));
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
|
}
|
|
@@ -472,11 +474,13 @@ namespace InABox.Database
|
|
|
if (entities.First() is INumericAutoIncrement<T> autoinc)
|
|
|
{
|
|
|
var prop = CoreUtils.GetPropertyFromExpression(autoinc.AutoIncrementField());
|
|
|
-
|
|
|
- var bRequired = false;
|
|
|
- foreach (var entity in entities)
|
|
|
- bRequired = bRequired || prop.GetValue(entity).Equals(0);
|
|
|
- if (bRequired)
|
|
|
+
|
|
|
+ var requiredEntities = entities.Where(x =>
|
|
|
+ {
|
|
|
+ return object.Equals(prop.GetValue(x), 0) && (x.ID == Guid.Empty || x.HasOriginalValue(prop.Name));
|
|
|
+ }).ToList();
|
|
|
+
|
|
|
+ if (requiredEntities.Count > 0)
|
|
|
{
|
|
|
|
|
|
var row = Provider.Query(
|
|
@@ -487,13 +491,10 @@ namespace InABox.Database
|
|
|
).Rows.FirstOrDefault();
|
|
|
int newvalue = row != null ? row.Get<int>(prop.Name) : 0;
|
|
|
|
|
|
- foreach (var entity in entities)
|
|
|
+ foreach (var entity in requiredEntities)
|
|
|
{
|
|
|
- if (prop.GetValue(entity).Equals(0))
|
|
|
- {
|
|
|
- newvalue++;
|
|
|
- prop.SetValue(entity, newvalue);
|
|
|
- }
|
|
|
+ newvalue++;
|
|
|
+ prop.SetValue(entity, newvalue);
|
|
|
}
|
|
|
return true;
|
|
|
}
|