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


C# Provider.Flush方法代码示例

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


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

示例1: OrphanTest

        private static void OrphanTest()
        {
            CoincidentalConfiguration config = Provider.Configure
                .Connection("test.yap")
                .ActivationDepth(1)
                .Debugging;

            using (Provider db = new Provider())
            {
                if (File.Exists("test.yap")) File.Delete("test.yap");
                db.Initialise(config);

                UnTracked untracked = db.Store(new UnTracked { Name = "UnTracked" });
                UnTracked other		= db.Store(new UnTracked { Name = "Other" });
                Tracked tracked		= db.Store(new Tracked { Name = "Tracked", ReferenceCount = 10 });

                Console.WriteLine("Initial reference count = {0}", tracked.ReferenceCount);

                try
                {
                    using (db.Lock(tracked)) tracked.ReferenceCount = 10;
                }
                catch(Exception e)
                {
                    Console.WriteLine("Exception caught: {0}", e.Message);
                }

                using (db.Lock(untracked)) untracked.Item = tracked;
                Console.WriteLine("Single reference added, count = {0}", tracked.ReferenceCount);

                using (db.Lock(other)) other.Item = tracked;
                Console.WriteLine("Single reference added to other, count = {0}", tracked.ReferenceCount);

                using (db.Lock(untracked.ItemList)) untracked.ItemList.Add(tracked);
                Console.WriteLine("Added to list, count = {0}", tracked.ReferenceCount);

                using (db.Lock(untracked)) untracked.Item = null;
                Console.WriteLine("Single reference removed, count = {0}", tracked.ReferenceCount);
            }

            using (Provider db = new Provider())
            {
                db.Initialise(config);

                UnTracked untracked = db.Get<UnTracked>(u => u.Name == "UnTracked");
                Tracked tracked		= db.Get<Tracked>(t => t.Name == "Tracked");

                Console.WriteLine("Closed and opened new provider, count = {0}", tracked.ReferenceCount);

                using (db.Lock(untracked.ItemList)) untracked.ItemList.Remove(tracked);
                Console.WriteLine("Removed from list, count = {0}", tracked.ReferenceCount);

                using (db.Lock(untracked)) untracked.Item = tracked;
                Console.WriteLine("Single reference added, count = {0}", tracked.ReferenceCount);
            }

            config = config.AutomaticOrphanPurge;

            using (Provider db = new Provider())
            {
                db.Initialise(config);

                UnTracked untracked = db.Get<UnTracked>(u => u.Name == "UnTracked");
                UnTracked other		= db.Get<UnTracked>(u => u.Name == "Other");
                Tracked tracked		= db.Get<Tracked>(t => t.Name == "Tracked");

                Console.WriteLine("Closed and opened new provider with automatic orphan purge enabled, count = {0}", tracked.ReferenceCount);

                db.Delete(other);
                Console.WriteLine("Deleted other, count = {0}", tracked.ReferenceCount);

                using (db.Lock(untracked)) untracked.Item = null;
                Console.WriteLine("Single reference removed, count = {0}", tracked.ReferenceCount);

                db.Flush();

                tracked = db.Get<Tracked>(t => t.Name == "Tracked");

                if (tracked == null) 	Console.WriteLine("Attempted to re-acquire tracked item, but it was successfully purged");
                else 					Console.WriteLine("Managed to re-acquire tracked item, automatic purging failed!");
            }
        }
开发者ID:parnham,项目名称:coincidental,代码行数:82,代码来源:Main.cs


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