- 优化插入判断主键,且为 Guid/Guid? 类型,并且值为 null/Guid.Empty 时,将插入的值变为 FreeUtil.NewMongodbId()

This commit is contained in:
28810
2019-03-04 20:45:19 +08:00
parent 24987ad2e9
commit a189b6abba
6 changed files with 24 additions and 15 deletions

View File

@ -80,7 +80,13 @@ namespace FreeSql.Internal.CommonProvider {
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
if (colidx2 > 0) sb.Append(", ");
sb.Append(_commonUtils.QuoteWriteParamter(col.CsType, $"{_commonUtils.QuoteParamterName(col.CsName)}{didx}"));
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}{didx}", col.CsType, _table.Properties.TryGetValue(col.CsName, out var tryp) ? tryp.GetValue(d) : null);
object val = null;
if (_table.Properties.TryGetValue(col.CsName, out var tryp)) {
val = tryp.GetValue(d);
if (col.Attribute.IsPrimary && (col.CsType == typeof(Guid) || col.CsType == typeof(Guid?))
&& (val == null || (Guid)val == Guid.Empty)) tryp.SetValue(d, val = FreeUtil.NewMongodbId());
}
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}{didx}", col.CsType, val);
++colidx2;
}
sb.Append(")");