//public static void BatchOperation<T>(this IEntityStore<T> store, IEnumerable<T> addDatas, IEnumerable<T> updateDatas, IEnumerable<T> deleteDatas) // where T : class //{ // if (addDatas != null) // { // store.Add(addDatas); // } // if (updateDatas != null) // { // store.Update(updateDatas); // } // if (deleteDatas != null) // { // store.Delete(deleteDatas); // } //} #region 树 public static void AddTreeNode <T, TKey>(this IEntityStore <T> store, T treeNode, string treePathSplitChar = ".") where T : class, ISelfTree <TKey> { _ = store ?? throw new ArgumentNullException(nameof(store)); _ = treeNode ?? throw new ArgumentNullException(nameof(treeNode)); if (default(TKey).Equals(treeNode.ParentId)) { //root node treeNode.Depth = 0; treeNode.NodePath = Hex36Convert.ConvertDecToHex36(0); treeNode.PathValue = 0; store.Add(treeNode); } else { var parent = store.FindByKey(treeNode.ParentId); if (parent == null) { throw new ApplicationException("can not find parent node."); } treeNode.Depth = parent.Depth + 1; string prefix = parent.NodePath + treePathSplitChar; //fid current max value var currentMax = store.Max(p => p.NodePath.StartsWith(prefix), p => (int?)p.PathValue); var nextPathValue = (currentMax.HasValue ? currentMax.Value : 0) + 1; treeNode.PathValue = nextPathValue; treeNode.NodePath = $"{parent.NodePath}{treePathSplitChar}{Hex36Convert.ConvertDecToHex36(nextPathValue)}"; store.Add(treeNode); } }
public void AddTwoBlog() { blogStore.Add(new Blog { Url = "http://www.baidu.com" }); blogStore.Add(new Blog { Url = "http://www.sina.com" }); }
public void AddTwoBookWithTransaction(bool throwError) { entityStore.Add(new Book { Id = DateTime.Now.Ticks, Name = "book" }); if (throwError) { throw new ApplicationException("throw some exception"); } entityStore.Add(new Book { Id = DateTime.Now.Ticks, Name = "book" }); }
public TEntity Store(TEntity entity) { AssertDispatcherThread(); var identity = _identifier.GetIdentity(entity); var val = _store.Get(identity); if (val == null) { _store.Add(entity); } return(entity); }
public TEntity Store(TEntity entity) { AssertDispatcherThread(); var identity = _identifier.GetIdentity(entity); var existing = _store.Get(identity); if (existing != null) { // Conflict resolution and merging } else { _store.Add(entity); } return(entity); }