private void SaveRecentSimilarArtist(SimilarArtistModel artistModel)
        {
            try
            {
                using (var session = DocumentStore.OpenSession())
                {
                    IRavenQueryable <SimilarArtistModel> artists = session.Query <SimilarArtistModel>();

                    if (artists.Any(a => a.Name.Equals(artistModel.Name, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        return;
                    }

                    int count = artists.Count();

                    if (count > 50)
                    {
                        var tooMany        = count - 50;
                        var tooManyArtists = artists.Take(tooMany);

                        foreach (var artist in tooManyArtists)
                        {
                            session.Delete(artist);
                        }
                    }

                    session.Store(artistModel);
                    session.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.Message, Category.Exception, Priority.Medium);
            }
        }
        /// <summary>
        /// 分页扩展方法
        /// </summary>
        /// <typeparam name="T">领域实体</typeparam>
        /// <param name="queryable">集合对象</param>
        /// <param name="predicate">查询条件</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="rowCount">总记录条数</param>
        /// <param name="pageCount">总页数</param>
        /// <returns>对象集合</returns>
        public static IRavenQueryable <T> ToPage <T>(this IRavenQueryable <T> queryable, Expression <Func <T, bool> > predicate, int pageIndex, int pageSize, out int rowCount, out int pageCount)
            where T : PlainEntity
        {
            IRavenQueryable <T> list = queryable.Where(predicate);

            rowCount  = list.Count();
            pageCount = (int)Math.Ceiling(rowCount * 1.0 / pageSize);
            return(list.OrderByDescending(x => x.AddedTime).Skip((pageIndex - 1) * pageSize).Take(pageSize));
        }
Beispiel #3
0
        private static void CheckListIsCorrect(string message, IRavenQueryable <Item> itemsInList, List <string> itemList)
        {
            //Console.WriteLine($"Checking {message}");
            var itemListCount = itemsInList.Count();

            if (itemListCount != itemList.Count)
            {
                Console.WriteLine("XXXXXXXXXXXXXX  Error: Expected {0} items in list, actual is: {1}", itemList.Count, itemListCount);
            }

            Console.WriteLine("There are {0} items in the some items list:", itemListCount);
            itemsInList.ForEach(PrintItem);
            Console.WriteLine("");
        }
Beispiel #4
0
        private int NumberOfDocumentsInDbByIndex(IDocumentStore aStore)
        {
            using (IDocumentSession session = aStore.OpenSession())
            {
                IRavenQueryable <DocumentView> query =
                    session.Query <Document, VersionedDocuments>()
                    .Customize(aCustomization => aCustomization.WaitForNonStaleResultsAsOfNow(TimeSpan.FromMinutes(10)))
                    .ProjectFromIndexFieldsInto <DocumentView>();

                foreach (DocumentView document in query)
                {
                    Debug.WriteLine(String.Format("Document {0} v.{1}", document.Id, document.Version));
                }

                return(query.Count());
            }
        }