本文整理汇总了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();
}
示例2: Constructor_SutIsUnitOfWork
public void Constructor_SutIsUnitOfWork()
{
// When
var sut = new DataContext();
// Then
Assert.IsAssignableFrom<IUnitOfWork>(sut);
sut.Dispose();
}
示例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();
}
示例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();
}
示例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();
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}