当前位置: 首页>>代码示例>>C#>>正文


C# DataContext.Dispose方法代码示例

本文整理汇总了C#中DataContext.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.Dispose方法的具体用法?C# DataContext.Dispose怎么用?C# DataContext.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataContext的用法示例。


在下文中一共展示了DataContext.Dispose方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitDatabase

        private static void InitDatabase()
        {
            Database.SetInitializer<DataContext>(new MigrateDatabaseToLatestVersion<DataContext, Configuration>());

            var context = new DataContext();
            context.Database.Initialize(false);
            context.Dispose();
        }
开发者ID:nikolaZ,项目名称:AreYouHungry,代码行数:8,代码来源:Global.asax.cs

示例2: Constructor_SutIsUnitOfWork

        public void Constructor_SutIsUnitOfWork()
        {
            // When
            var sut = new DataContext();

            // Then
            Assert.IsAssignableFrom<IUnitOfWork>(sut);
            sut.Dispose();
        }
开发者ID:ecampidoglio,项目名称:Expresso,代码行数:9,代码来源:DataContextTest.cs

示例3: GetPosts_ReturnsEmptyCollection

        public void GetPosts_ReturnsEmptyCollection(string databaseName)
        {
            // Given
            var sut = new DataContext(databaseName);

            // When
            var result = sut.Get<Post>();

            // Then
            Assert.Empty(result);
            sut.Database.Delete();
            sut.Dispose();
        }
开发者ID:ecampidoglio,项目名称:Expresso,代码行数:13,代码来源:DataContextTest.cs

示例4: GetPosts_DoesNotReturnNull

        public void GetPosts_DoesNotReturnNull(string databaseName)
        {
            // Given
            var sut = new DataContext(databaseName);

            // When
            var result = sut.Get<Post>();

            // Then
            Assert.NotNull(result);
            sut.Database.Delete();
            sut.Dispose();
        }
开发者ID:ecampidoglio,项目名称:Expresso,代码行数:13,代码来源:DataContextTest.cs

示例5: GetPageStructure

        internal static PageIndexDictionary GetPageStructure(int languageId) {
            var context = new DataContext();

            try {
                var pageIndexDictionary = new PageIndexDictionary(GetPages(context, languageId));
                return pageIndexDictionary;
            }
            catch (Exception e) {
                Logger.Write(e, Logger.Severity.Major);
                throw;
            }
            finally {
                context.Dispose();
            }
        }
开发者ID:KalikoCMS,项目名称:KalikoCMS.Core,代码行数:15,代码来源:PageData.cs

示例6: GetPropertiesForPage

        internal static PropertyCollection GetPropertiesForPage(Guid pageId, int languageId, int pageTypeId, int version, bool useCache) {
            var cacheName = GetCacheName(pageId, languageId, version);

            var propertyCollection = new PropertyCollection();
            List<PropertyItem> propertyItems = null;

            if (useCache) {
                propertyItems = CacheManager.Get<List<PropertyItem>>(cacheName);
            }

            if (propertyItems != null) {
                propertyCollection.Properties = propertyItems;
            }
            else {
                var context = new DataContext();

                try {
                    var properties = from p in context.Properties
                        join pp in context.PageProperties on new { PropertyId = p.PropertyId, PageId = pageId, LanguageId = languageId, Version = version } equals new { pp.PropertyId, pp.PageId, pp.LanguageId, pp.Version } into merge
                        from m in merge.DefaultIfEmpty()
                        where p.PageTypeId == pageTypeId
                        orderby p.SortOrder
                        select new PropertyItem {
                            PagePropertyId = m.PagePropertyId,
                            PropertyName = p.Name.ToLower(),
                            PropertyData = CreatePropertyData(p.PropertyTypeId, m.PageData),
                            PropertyId = p.PropertyId,
                            PropertyTypeId = p.PropertyTypeId
                        };
                    propertyCollection.Properties = properties.ToList();
                }
                finally {
                    context.Dispose();
                }

                if (useCache) {
                    CacheManager.Add(cacheName, propertyCollection.Properties, CachePriority.Medium, 30, true, true);
                }
            }

            return propertyCollection;
        }
开发者ID:dotnetwiz,项目名称:KalikoCMS.Core,代码行数:42,代码来源:PropertyData.cs

示例7: DeletePage

        //TODO: Add language parameters when going multi-language
        internal static Collection<Guid> DeletePage(Guid pageId) {
            var pageIds = PageFactory.GetPageTreeFromPage(pageId, PublishState.All).PageIds;
            pageIds.Add(pageId);

            var context = new DataContext();

            try {
                var deleteTimeStamp = DateTime.Now.ToUniversalTime();

                // TODO: Säkerställ att detta funkar mot stora mängder!!
                context.PageInstances.Where(p => pageIds.Contains(p.PageId)).UpdateAll(p => p.Set(v => v.DeletedDate, v => deleteTimeStamp));
            }
            finally {
                context.Dispose();
            }

            return pageIds;
        }
开发者ID:KalikoCMS,项目名称:KalikoCMS.Core,代码行数:19,代码来源:PageData.cs

示例8: UpdateStructure

        internal static void UpdateStructure(List<PageIndexItem> changedItems) {
            var pageItems = changedItems.ToDictionary(i => i.PageId);
            var pageInstanceItems = changedItems.ToDictionary(i => i.PageInstanceId);
            var pageIds = pageItems.Keys;
            var pageInstanceIds = pageInstanceItems.Keys;

            var context = new DataContext();

            try {
                var pages = context.Pages.Where(p => pageIds.Contains(p.PageId));
                foreach (var page in pages) {
                    var indexItem = pageItems[page.PageId];
                    page.TreeLevel = indexItem.TreeLevel;
                    page.ParentId = indexItem.ParentId;
                    page.RootId = indexItem.RootId;
                }

                var pageInstances = context.PageInstances.Where(p => pageInstanceIds.Contains(p.PageInstanceId));
                foreach (var pageInstance in pageInstances) {
                    var indexItem = pageInstanceItems[pageInstance.PageInstanceId];
                    pageInstance.PageUrl = indexItem.UrlSegment;
                }
                context.SaveChanges();
            }
            finally {
                context.Dispose();
            }
        }
开发者ID:KalikoCMS,项目名称:KalikoCMS.Core,代码行数:28,代码来源:PageData.cs

示例9: GetPosts_WithNewPostAndEagerLoadedTag_ReturnsPostWithTheSameTag

        public void GetPosts_WithNewPostAndEagerLoadedTag_ReturnsPostWithTheSameTag(
            Post post,
            Tag tag,
            string databaseName)
        {
            // Given
            post.Tags.Add(tag);
            var sut = new DataContext(databaseName);

            // When
            sut.RegisterAdded(post);
            sut.SaveChanges();
            var result = sut.Get<Post>("Tags").SingleOrDefault();

            // Then
            Assert.True(post.Tags.SequenceEqual(result.Tags));
            sut.Database.Delete();
            sut.Dispose();
        }
开发者ID:ecampidoglio,项目名称:Expresso,代码行数:19,代码来源:DataContextTest.cs

示例10: RegisterModified_WithNullPost_ThrowsArgumentNullException

        public void RegisterModified_WithNullPost_ThrowsArgumentNullException(string databaseName)
        {
            // Given
            var sut = new DataContext(databaseName);

            // Then
            Assert.Throws<ArgumentNullException>(() => sut.RegisterModified<Post>(null));
            sut.Database.Delete();
            sut.Dispose();
        }
开发者ID:ecampidoglio,项目名称:Expresso,代码行数:10,代码来源:DataContextTest.cs

示例11: RegisterModified_WithModifiedPost_PersistsPost

        public void RegisterModified_WithModifiedPost_PersistsPost(
            string databaseName,
            Post post,
            string modifiedValue)
        {
            // Given
            var sut = new DataContext(databaseName);
            sut.RegisterAdded(post);
            sut.Commit();

            // When
            post.Title = modifiedValue;
            sut.RegisterModified(post);
            sut.Commit();
            var result = sut.Get<Post>().FirstOrDefault();

            // Then
            Assert.Equal(post, result);
            sut.Database.Delete();
            sut.Dispose();
        }
开发者ID:ecampidoglio,项目名称:Expresso,代码行数:21,代码来源:DataContextTest.cs

示例12: RegisterDeleted_WithPost_RemovesPost

        public void RegisterDeleted_WithPost_RemovesPost(
            string databaseName,
            Post post)
        {
            // Given
            var sut = new DataContext(databaseName);
            sut.RegisterAdded(post);
            sut.Commit();

            // When
            sut.RegisterDeleted(post);
            sut.Commit();
            var result = sut.Get<Post>().Any();

            // Then
            Assert.False(result);
            sut.Database.Delete();
            sut.Dispose();
        }
开发者ID:ecampidoglio,项目名称:Expresso,代码行数:19,代码来源:DataContextTest.cs

示例13: GetPosts_WithNewPost_ReturnsCollectionWithOneElement

        public void GetPosts_WithNewPost_ReturnsCollectionWithOneElement(
            Post post,
            string databaseName)
        {
            // Given
            var sut = new DataContext(databaseName);

            // When
            sut.RegisterAdded(post);
            sut.SaveChanges();
            var result = sut.Get<Post>();

            // Then
            Assert.Equal(1, result.Count());
            sut.Database.Delete();
            sut.Dispose();
        }
开发者ID:ecampidoglio,项目名称:Expresso,代码行数:17,代码来源:DataContextTest.cs

示例14: GetPosts_WithNewPostAndNonExistentEagerLoadedProperty_Throws

        public void GetPosts_WithNewPostAndNonExistentEagerLoadedProperty_Throws(
            Post post,
            string propertyName,
            string databaseName)
        {
            // Given
            var sut = new DataContext(databaseName);

            // When
            sut.RegisterAdded(post);
            sut.SaveChanges();

            // Then
            Assert.Throws<InvalidOperationException>(() => sut.Get<Post>(propertyName).Any());
            sut.Database.Delete();
            sut.Dispose();
        }
开发者ID:ecampidoglio,项目名称:Expresso,代码行数:17,代码来源:DataContextTest.cs


注:本文中的DataContext.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。