public void FetchStrategy_May_Include_Multiple_Levels_First_Syntax()
        {
            // This is a non-sense example because the Email property is not another table, but it works the exact same
            var strategy = new GenericFetchStrategy<Contact>()
                .Include(p => p.EmailAddresses.First().Email);

            strategy.IncludePaths.ShouldContain("EmailAddresses.Email");
        }
        public void FetchStrategy_May_Include_Multiple_References()
        {
            var strategy = new GenericFetchStrategy<Contact>()
                .Include(p => p.EmailAddresses)
                .Include(p => p.PhoneNumbers);

            strategy.IncludePaths.ShouldContain("EmailAddresses");
            strategy.IncludePaths.ShouldContain("PhoneNumbers");
            strategy.IncludePaths.Count().ShouldEqual(2);
        }
        public void FetchStrategy_May_Include_String_Property_Names()
        {
            // This is a non-sense example because the Email property is not another table, but it works the exact same
            var strategy = new GenericFetchStrategy<Contact>()
                .Include("EmailAddresses")
                .Include("PhoneNumbers");

            strategy.IncludePaths.ShouldContain("EmailAddresses");
            strategy.IncludePaths.ShouldContain("PhoneNumbers");
            strategy.IncludePaths.Count().ShouldEqual(2);
        }
Example #4
0
        protected IFetchStrategy <T> InstanciateFetchStrategy(IFetchStrategy <T> strategy)
        {
            var thisPaths    = FetchStrategy != null ? FetchStrategy.IncludePaths : new List <string>();
            var paramPaths   = strategy != null ? strategy.IncludePaths : new List <string>();
            var includePaths = thisPaths.Union(paramPaths);

            var newStrategy = new GenericFetchStrategy <T>();

            foreach (var includePath in includePaths)
            {
                newStrategy.Include(includePath);
            }

            return(newStrategy);
        }
        public void EfCore_GetAll_With_Includes_In_Strategy_String_LazyLoads_Email()
        {
            var repository = new EfCoreRepository <Contact, string>(dbContext);

            var strategy = new GenericFetchStrategy <Contact>();

            strategy.Include(x => x.EmailAddresses);

            var contact = repository.GetAll(strategy).First();

            contact.Name.ShouldBe("Test User 1");
            dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
            contact.EmailAddresses.First().Email.ShouldBe("*****@*****.**");
            dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
        }
        public void GetMany_List_Should_Return_Multiple_Items_With_Strategy(IRepository <Contact, string> repository)
        {
            var strategy = new GenericFetchStrategy <Contact>();

            strategy.Include(c => c.EmailAddresses);


            for (var i = 1; i <= 5; i++)
            {
                var contact = new Contact {
                    ContactId = i.ToString(), Name = "Test User " + i
                };
                repository.Add(contact);
            }

            var items = repository.GetMany(new[] { "1", "3", "4", "5" }.ToList(), strategy);

            items.Count().ShouldBe(4);
        }
Example #7
0
        public void DeleteForm(string keyValue)
        {
            var    id = Convert.ToInt64(keyValue);
            var    genericFetchStrategy = new GenericFetchStrategy <WxNews>().Include(p => p.WxNewsItems);
            WxNews wxNews = wxNewsRepository.Get(id, genericFetchStrategy);

            if (!string.IsNullOrEmpty(wxNews.MediaId))
            {
                string            appId             = WxOperatorProvider.Provider.GetCurrent().AppId;
                AccessTokenResult accessTokenResult = AccessTokenContainer.GetAccessTokenResult(appId);
                var wxJsonResult = MediaApi.DeleteForeverMedia(accessTokenResult.access_token, wxNews.MediaId, 10000);
                if (wxJsonResult.ErrorCodeValue == 0)
                {
                    wxNews.MediaId      = null;
                    wxNews.DeletedMark  = true;
                    wxNews.DeletionTime = DateTime.Now;
                    foreach (WxNewsItem item in wxNews.WxNewsItems)
                    {
                        item.DeletedMark  = true;
                        item.DeletionTime = DateTime.Now;
                    }
                    wxNewsRepository.Update(wxNews);
                }
            }
            else
            {
                wxNews.MediaId      = null;
                wxNews.DeletedMark  = true;
                wxNews.DeletionTime = DateTime.Now;
                foreach (WxNewsItem item in wxNews.WxNewsItems)
                {
                    item.DeletedMark  = true;
                    item.DeletionTime = DateTime.Now;
                }
                wxNewsRepository.Update(wxNews);
            }
        }
        public void GetAll_With_Includes_In_Strategy_String_LazyLoads_Email()
        {
            dbContext.Configuration.LazyLoadingEnabled = true;
            dbContext.Database.Log = sql =>
            {
                if (sql.Contains("SELECT"))
                {
                    queries.Add(sql);
                }
            };
            var repository = new MyEfRepository(dbContext);


            var strategy = new GenericFetchStrategy <Contact>();

            strategy.Include(x => x.EmailAddresses);

            var contact = repository.GetAll(strategy).First();

            contact.Name.ShouldEqual("Test User 1");
            queries.Count().ShouldEqual(1);
            contact.EmailAddresses.First().Email.ShouldEqual("*****@*****.**");
            queries.Count().ShouldEqual(1);
        }
Example #9
0
 public Specification(Expression <Func <T, bool> > predicate)
 {
     Predicate     = predicate;
     FetchStrategy = new GenericFetchStrategy <T>();
 }
Example #10
0
 protected CompositeSpecification(Expression <Func <T, bool> > predicate)
 {
     FetchStrategy = new GenericFetchStrategy <T>();
     Predicate     = predicate;
 }
Example #11
0
        public void FetchStrategy_AsNoTracking_Set_AsNoTracking()
        {
            var strategy = new GenericFetchStrategy <Contact>().AsNoTracking();

            strategy.NoTracking.ShouldBeTrue();
        }
Example #12
0
        public void SubmitForm(WxNewsInputDto wxNewsInputDto, string keyValue)
        {
            string appId  = WxOperatorProvider.Provider.GetCurrent().AppId;
            WxNews wxNews = new WxNews();

            if (!string.IsNullOrEmpty(keyValue))
            {
                long newsId = Convert.ToInt64(keyValue);
                var  genericFetchStrategy = new GenericFetchStrategy <WxNews>().Include(p => p.WxNewsItems.First().Thumb);
                wxNews = wxNewsRepository.Get(newsId, genericFetchStrategy);
                wxNews.LastModificationTime = DateTime.Now;
                wxNewsRepository.Update(wxNews);
                foreach (WxNewsItemInputDto wxNewsItemInputDto in wxNewsInputDto.WxNewsItems)
                {
                    if (!string.IsNullOrEmpty(wxNewsItemInputDto.Id))
                    {
                        long       newsItemId = Convert.ToInt64(wxNewsItemInputDto.Id);
                        WxNewsItem wxNewsItem = wxNewsItemRepository.Get(newsItemId);
                        wxNewsItem.NewsId           = wxNews.Id;
                        wxNewsItem.Title            = wxNewsItemInputDto.Title;
                        wxNewsItem.Author           = wxNewsItemInputDto.Author;
                        wxNewsItem.Digest           = wxNewsItemInputDto.Digest;
                        wxNewsItem.Content          = wxNewsItemInputDto.Content;
                        wxNewsItem.ContentSourceUrl = wxNewsItemInputDto.ContentSourceUrl;
                        wxNewsItem.ThumbId          = Convert.ToInt64(wxNewsItemInputDto.Thumb.Id);
                        if (!string.IsNullOrEmpty(wxNewsItemInputDto.Thumb.MediaId))
                        {
                            wxNewsItem.ShowCoverPic = 1;
                        }
                        else
                        {
                            wxNewsItem.ShowCoverPic = 0;
                        }
                        wxNewsItem.Index                = wxNewsItemInputDto.Index;
                        wxNewsItem.NeedOpenComment      = wxNewsItemInputDto.NeedOpenComment;
                        wxNewsItem.OnlyFansCanComment   = wxNewsItemInputDto.OnlyFansCanComment;
                        wxNewsItem.LastModificationTime = DateTime.Now;
                        wxNewsItemRepository.Update(wxNewsItem);
                    }
                    else
                    {
                        WxNewsItem wxNewsItem = new WxNewsItem();
                        wxNewsItem.Id               = IdWorkerHelper.GenId64();
                        wxNewsItem.NewsId           = wxNews.Id;
                        wxNewsItem.Title            = wxNewsItemInputDto.Title;
                        wxNewsItem.Author           = wxNewsItemInputDto.Author;
                        wxNewsItem.Digest           = wxNewsItemInputDto.Digest;
                        wxNewsItem.Content          = wxNewsItemInputDto.Content;
                        wxNewsItem.ContentSourceUrl = wxNewsItemInputDto.ContentSourceUrl;
                        wxNewsItem.ThumbId          = Convert.ToInt64(wxNewsItemInputDto.Thumb.Id);
                        if (!string.IsNullOrEmpty(wxNewsItemInputDto.Thumb.Id))
                        {
                            wxNewsItem.ShowCoverPic = 1;
                        }
                        else
                        {
                            wxNewsItem.ShowCoverPic = 0;
                        }
                        wxNewsItem.Index              = wxNewsItemInputDto.Index;
                        wxNewsItem.NeedOpenComment    = wxNewsItemInputDto.NeedOpenComment;
                        wxNewsItem.OnlyFansCanComment = wxNewsItemInputDto.OnlyFansCanComment;
                        wxNewsItem.DeletedMark        = false;
                        wxNewsItem.CreationTime       = DateTime.Now;
                        wxNewsItemRepository.Add(wxNewsItem);
                    }
                }
            }
            else
            {
                wxNews.Id           = IdWorkerHelper.GenId64();
                wxNews.AppId        = appId;
                wxNews.DeletedMark  = false;
                wxNews.CreationTime = DateTime.Now;
                wxNews.WxNewsItems  = new List <WxNewsItem>();
                foreach (WxNewsItemInputDto wxNewsItemInputDto in wxNewsInputDto.WxNewsItems)
                {
                    WxNewsItem wxNewsItem = new WxNewsItem();
                    wxNewsItem.Id               = IdWorkerHelper.GenId64();
                    wxNewsItem.NewsId           = wxNews.Id;
                    wxNewsItem.Title            = wxNewsItemInputDto.Title;
                    wxNewsItem.Author           = wxNewsItemInputDto.Author;
                    wxNewsItem.Digest           = wxNewsItemInputDto.Digest;
                    wxNewsItem.Content          = wxNewsItemInputDto.Content;
                    wxNewsItem.ContentSourceUrl = wxNewsItemInputDto.ContentSourceUrl;
                    wxNewsItem.ThumbId          = Convert.ToInt64(wxNewsItemInputDto.Thumb.Id);
                    if (!string.IsNullOrEmpty(wxNewsItemInputDto.Thumb.Id))
                    {
                        wxNewsItem.ShowCoverPic = 1;
                    }
                    else
                    {
                        wxNewsItem.ShowCoverPic = 0;
                    }
                    wxNewsItem.Index              = wxNewsItemInputDto.Index;
                    wxNewsItem.NeedOpenComment    = wxNewsItemInputDto.NeedOpenComment;
                    wxNewsItem.OnlyFansCanComment = wxNewsItemInputDto.OnlyFansCanComment;
                    wxNewsItem.DeletedMark        = false;
                    wxNewsItem.CreationTime       = DateTime.Now;
                    wxNews.WxNewsItems.Add(wxNewsItem);
                }
                wxNewsRepository.Add(wxNews);
            }
        }