mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
- 优化插入判断主键,且为 Guid/Guid? 类型,并且值为 null/Guid.Empty 时,将插入的值变为 FreeUtil.NewMongodbId()
This commit is contained in:
@ -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(")");
|
||||
|
Reference in New Issue
Block a user