/// <summary> /// 新增或更新根实体对象 /// </summary> /// <param name="propertyValues">待更新属性值队列</param> /// <param name="throwIfFound">如果为 true, 则发现已存在时引发 InvalidOperationException,否则覆盖更新它</param> /// <param name="throwIfNotOwn">如果为 true, 则发现制单人不是自己时引发 InvalidOperationException,否则覆盖更新它</param> protected override Task PutKernel(IDictionary <string, object> propertyValues, bool throwIfFound = false, bool?throwIfNotOwn = null) { if (Kernel != null) { if (throwIfFound && !throwIfNotOwn.HasValue || throwIfNotOwn.HasValue && throwIfNotOwn.Value && (long)Kernel.GetValue("Originator") != User.Identity.Id) { throw new System.ComponentModel.DataAnnotations.ValidationException("不允许重复新增!"); } else { OnKernelOperating(ExecuteAction.Update, out object tag); Kernel.UpdateSelf(propertyValues); OnKernelOperated(ExecuteAction.Update, tag); } } else if (this is IGrainWithIntegerKey) { OnKernelOperating(ExecuteAction.Insert, out object tag); TreeEntityBase <TKernel> .NewRoot(Database, propertyValues).InsertSelf(PrimaryKeyLong); OnKernelOperated(ExecuteAction.Insert, tag); } else { OnKernelOperating(ExecuteAction.Insert, out object tag); TreeEntityBase <TKernel> .NewRoot(Database, propertyValues).InsertSelf(); OnKernelOperated(ExecuteAction.Insert, tag); } return(Task.CompletedTask); }
Task <int> IEntityGrain <TKernel> .PatchKernel(params NameValue[] propertyValues) { return(Task.FromResult(Kernel != null ? Kernel.UpdateSelf(propertyValues) : this is IGrainWithIntegerKey ? TreeEntityBase <TKernel> .NewRoot(Database, Id, propertyValues).InsertSelf() : TreeEntityBase <TKernel> .NewRoot(Database, propertyValues).InsertSelf())); }
/// <summary> /// 获取根实体对象 /// </summary> /// <param name="autoNew">不存在则新增</param> /// <returns>根实体对象</returns> protected override Task <TKernel> FetchKernel(bool autoNew = false) { return(Task.FromResult(Kernel == null && autoNew ? this is IGrainWithIntegerKey ? TreeEntityBase <TKernel> .NewRoot(Database, NameValue.Set <TKernel>(p => p.PrimaryKeyLong, PrimaryKeyLong)) : TreeEntityBase <TKernel> .NewRoot(Database) : Kernel)); }
/// <summary> /// 更新根实体对象(如不存在则新增) /// </summary> /// <param name="propertyValues">待更新属性值队列</param> protected override void PatchKernel(IDictionary <string, object> propertyValues) { if (Kernel != null) { Kernel.UpdateSelf(propertyValues); } else if (this is IGrainWithIntegerKey || this is IGrainWithIntegerCompoundKey) { TreeEntityBase <TKernel> .NewRoot(Database, Id, propertyValues).InsertSelf(); } else { TreeEntityBase <TKernel> .NewRoot(Database, propertyValues).InsertSelf(); } }