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


C# DatabaseContext.GetRepository方法代码示例

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


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

示例1: CreateVersionWithArrangement

        public void CreateVersionWithArrangement()
        {
            int arrangementId;
            using (DatabaseContext ctx = new DatabaseContext())
            {
                var arrangementDao = ctx.GetRepository<ArrangementRepository>();

                Arrangement arrangement = arrangementDao.Add();
                arrangement.BpNumber = "123456789";
                arrangement.Name = "Koops";

                ctx.SaveChanges();
                arrangementId = arrangement.Id;
            }

            using (DatabaseContext ctx = new DatabaseContext())
            {
                var arrangementDao = ctx.GetRepository<ArrangementRepository>();
                var versionDao = ctx.GetRepository<ArrangementVersionRepository>();

                var arrangement = arrangementDao.GetSingle(a => a.Id == arrangementId);

                ArrangementVersion version = versionDao.Add();
                version.Version = 1;
                arrangement.Versions.Add(version);

                ctx.SaveChanges();
            }

            using (DatabaseContext ctx = new DatabaseContext())
            {
                var arrangementDao = ctx.GetRepository<ArrangementRepository>();
                var arrangement = arrangementDao.GetSingle(a => a.Id == arrangementId);

                Assert.IsNotEmpty(arrangement.Versions);
                Assert.AreEqual(1, arrangement.Versions.Single().Id);

                ctx.SaveChanges();
            }
        }
开发者ID:phoogestijn,项目名称:EntityFrameworkSandbox,代码行数:40,代码来源:ArrangementVersionTests.cs

示例2: CreateUserWithMultipleArrangements

        public void CreateUserWithMultipleArrangements()
        {
            Arrangement arr1, arr2;
            using (DatabaseContext ctx = new DatabaseContext())
            {
                var arrangementDao = ctx.GetRepository<ArrangementRepository>();
                {
                    arr1 = arrangementDao.Add();
                    arr1.BpNumber = "1";
                    arr1.Name = "Vendor 1";

                    arr2 = arrangementDao.Add();
                    arr2.BpNumber = "2";
                    arr2.Name = "Vendor 2";
                }

                var userDao = ctx.GetRepository<UserRepository>();
                var user = userDao.Add();
                {
                    user.FullName = "Everest BV";
                    user.Email = "[email protected]";
                    user.UserName = "everest_nl";

                    user.Arrangements.Add(arr1);
                    user.Arrangements.Add(arr2);
                }

                ctx.SaveChanges();

                {
                    Assert.AreEqual("Everest BV", user.FullName);
                    Assert.AreEqual("[email protected]", user.Email);
                    Assert.AreEqual("everest_nl", user.UserName);

                    Assert.AreEqual(2, user.Arrangements.Count());
                    Assert.AreEqual(1, arr1.Users.Count);
                    Assert.AreEqual(1, arr2.Users.Count);
                }
            }
        }
开发者ID:phoogestijn,项目名称:EntityFrameworkSandbox,代码行数:40,代码来源:UserTests.cs

示例3: CreateVersionWithoutArrangement

        public void CreateVersionWithoutArrangement()
        {
            using (DatabaseContext ctx = new DatabaseContext())
            {
                var dao = ctx.GetRepository<ArrangementVersionRepository>();

                ArrangementVersion version = dao.Add();
                version.Version = 1;
                // Oeps, no arrangement version is set !!

                ctx.SaveChanges();
            }
        }
开发者ID:phoogestijn,项目名称:EntityFrameworkSandbox,代码行数:13,代码来源:ArrangementVersionTests.cs

示例4: CreateUserWithoutArrangement

        public void CreateUserWithoutArrangement()
        {
            using (DatabaseContext ctx = new DatabaseContext())
            {
                var userRepos = ctx.GetRepository<UserRepository>();
                var user = userRepos.Add();
                {
                    user.Email = "[email protected]";
                    user.FullName = "Everest BV";
                    user.UserName = "everest_nl";
                }

                ctx.SaveChanges();
            }
        }
开发者ID:phoogestijn,项目名称:EntityFrameworkSandbox,代码行数:15,代码来源:UserTests.cs


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