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


C# MyEntityContext.DeleteObject方法代码示例

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


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

示例1: TestDeletionOfEntities

        public void TestDeletionOfEntities()
        {
            var storeName = Guid.NewGuid().ToString();
            var context = new MyEntityContext("type=embedded;storesdirectory=c:\\brightstar;storename=" + storeName);

            var p1 = context.Persons.Create();
            p1.Name = "jen";

            var skillIds = new List<string>();
            for(var i = 0; i < 5 ;i++)
            {
                var skill = context.Skills.Create();
                skill.Name = "Skill " + i;
                if(i < 3)
                {
                    p1.Skills.Add(skill);
                }
                skillIds.Add(skill.Id);
            }
            context.SaveChanges();
            var jenId = p1.Id;

            context = new MyEntityContext("type=embedded;storesdirectory=c:\\brightstar;storename=" + storeName);
            var jen = context.Persons.Where(p => p.Id.Equals(jenId)).FirstOrDefault();

            Assert.IsNotNull(jen);
            Assert.AreEqual("jen", jen.Name);
            Assert.AreEqual(3, jen.Skills.Count);

            var allSkills = context.Skills;
            Assert.AreEqual(5, allSkills.Count());
            foreach(var s in allSkills)
            {
                context.DeleteObject(s);
            }
            context.SaveChanges();

            context = new MyEntityContext("type=embedded;storesdirectory=c:\\brightstar;storename=" + storeName);
            allSkills = context.Skills;
            Assert.AreEqual(0, allSkills.Count());
            
            jen = context.Persons.Where(p => p.Id.Equals(jenId)).FirstOrDefault();

            Assert.IsNotNull(jen);
            Assert.AreEqual("jen", jen.Name);
            Assert.AreEqual(0, jen.Skills.Count, "Person still has 3 skills even after skills are deleted");

           context.DeleteObject(jen);
            context.SaveChanges();

            jen = context.Persons.Where(p => p.Id.Equals(jenId)).FirstOrDefault();
            Assert.IsNull(jen);
        }
开发者ID:Garwin4j,项目名称:BrightstarDB,代码行数:53,代码来源:SimpleContextTests.cs

示例2: TestDeleteEntityInSameContext

        public void TestDeleteEntityInSameContext()
        {
            var storeName = "DeleteEntityInSameContext_" + DateTime.Now.Ticks;
            using (
                var context = new MyEntityContext("type=embedded;storesdirectory=c:\\brightstar;storename=" + storeName)
                )
            {
                var alice = context.Persons.Create();
                alice.Name = "Alice";
                context.SaveChanges();

                string aliceId = alice.Id;

                // Delete object
                context.DeleteObject(alice);
                context.SaveChanges();

                // Object should no longer be discoverable
                Assert.That(context.Persons.FirstOrDefault(p => p.Id.Equals(aliceId)), Is.Null);
            }
        }
开发者ID:kowalot,项目名称:BrightstarDB,代码行数:21,代码来源:SimpleContextTests.cs

示例3: TestDeleteEntity

        public void TestDeleteEntity()
        {
            var storeName = Guid.NewGuid().ToString();
            var context = new MyEntityContext("type=embedded;storesdirectory=c:\\brightstar;storename=" + storeName);
            
            // create person
            var p1 = context.Persons.Create();
            p1.Name = "jen";
            context.SaveChanges();

            // retrieve object
            var jenId = p1.Id;
            context = new MyEntityContext("type=embedded;storesdirectory=c:\\brightstar;storename=" + storeName);
            var jen = context.Persons.Where(p => p.Id.Equals(jenId)).FirstOrDefault();

            context.DeleteObject(jen);
            context.SaveChanges();

            Assert.AreEqual(0, context.Persons.Count());
        }
开发者ID:Garwin4j,项目名称:BrightstarDB,代码行数:20,代码来源:SimpleContextTests.cs

示例4: TestDeleteEntity

        public void TestDeleteEntity()
        {
            var storeName = Guid.NewGuid().ToString();
            string jenId;
            using (
                var context = new MyEntityContext("type=embedded;storesdirectory=c:\\brightstar;storename=" + storeName)
                )
            {

                // create person
                var p1 = context.Persons.Create();
                p1.Name = "jen";
                context.SaveChanges();

                // retrieve object
                jenId = p1.Id;
            }

            using (
                var context = new MyEntityContext("type=embedded;storesdirectory=c:\\brightstar;storename=" + storeName)
                )
            {
                var jen = context.Persons.FirstOrDefault(p => p.Id == jenId);

                context.DeleteObject(jen);
                context.SaveChanges();

                jen = context.Persons.FirstOrDefault(p => p.Id == jenId);
                Assert.That(jen, Is.Null);
            }
        }
开发者ID:kowalot,项目名称:BrightstarDB,代码行数:31,代码来源:SimpleContextTests.cs


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