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


C# GenericRepository类代码示例

本文整理汇总了C#中GenericRepository的典型用法代码示例。如果您正苦于以下问题:C# GenericRepository类的具体用法?C# GenericRepository怎么用?C# GenericRepository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: AddTaxToGirl

        private static void AddTaxToGirl(string firstname, string lastname, int tax)
        {
            var girlRepo = new GenericRepository<Girl>(new GirlsAgencyContext());
            var girl = girlRepo.Search(g => g.FirstName == firstname && g.LastName == lastname).FirstOrDefault();

            if (girl == null)
            {
                throw new ApplicationException("Girl does not exists/found");
            }

            var girlTaxes = new GirlsTaxesEntities();

            string girlFullName = girl.FirstName + " " + girl.LastName;

            var girlTax = GetAssignTax(girlFullName, girlTaxes);

            if (girlTax == null)
            {
                girlTaxes.GirlsTaxes.Add(new GirlsTax
                {
                    GirlName = girlFullName,
                    Tax = tax
                });
            }
            else
            {
                girlTax.Tax = tax;
            }

            girlTaxes.SaveChanges();
        }
开发者ID:TeamCurrant,项目名称:GirlsAgency,代码行数:31,代码来源:CommandEngine.cs

示例2: Get

 public ICollection<Test> Get()
 {
     var db = new StudentSystemDbContext();
     var testsRepo = new GenericRepository<Test>(db);
     List<Test> tests = testsRepo.All().ToList();
     return tests;
 }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:7,代码来源:TestsController.cs

示例3: TestCreateBusiness

        public void TestCreateBusiness()
        {
            var a = EntityHelper.GetAccount("first", "lastName");
            var b = EntityHelper.GetBusiness("business1", Category.ActiveLife);

            using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>())
            {
                using (ISession Session = Scope.OpenSession())
                {
                    Session.Transaction.Begin();
                    IRepository r = new GenericRepository(Session);
                    EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator());

                    IDataService ds = new DataService(null, bds, null, null, null, null, null, null, null, new UnitOfWork(Session));
                    BusinessActions ba = new BusinessActions(a, ds, new PraLoup.Infrastructure.Logging.Log4NetLogger(), null);
                    ba.CreateBusiness(b, a, Role.BusinessAdmin);
                    Session.Transaction.Commit();
                }

                using (ISession Session = Scope.OpenSession())
                {
                    IRepository r = new GenericRepository(Session);
                    EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator());

                    var b1 = bds.Find(b.Id);
                    Assert.IsNotNull(b1);
                    Assert.AreEqual(b, b1);
                }
            }
        }
开发者ID:akoesnan,项目名称:PraLoup,代码行数:30,代码来源:BusinessActionsTest.cs

示例4: Get

 public ICollection<Course> Get()
 {
     var db = new StudentSystemDbContext();
     var coursesRepo = new GenericRepository<Course>(db);
     List<Course> courses = coursesRepo.All().ToList();
     return courses;
 }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:7,代码来源:CoursesController.cs

示例5: Get

 public ICollection<Student> Get()
 {
     var db = new StudentSystemDbContext();
     var studentsRepo = new GenericRepository<Student>(db);
     List<Student> students = studentsRepo.All().ToList();
     return students;
 }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:7,代码来源:StudentsController.cs

示例6: Post

        public IHttpActionResult Post(TestRequestModel model)
        {
            if (model == null)
            {
                return this.BadRequest();
            }

            var db = new StudentSystemDbContext();
            var testsRepo = new GenericRepository<Test>(db);
            var coursesRepo = new GenericRepository<Course>(db);
            List<Course> allCourses = coursesRepo.All().ToList();
            var testCourse = new Course
            {
                Name = model.Course.Name,
                Description = model.Course.Description
            };

            var testToAdd = new Test
            {
                Course = testCourse
            };

            testsRepo.Add(testToAdd);
            testsRepo.SaveChanges();
            return this.Ok();
        }
开发者ID:vassildinev,项目名称:Web-Services,代码行数:26,代码来源:TestsController.cs

示例7: Constructor_If_Passed_Context_Is_Null_Must_Throw_Exception

 public void Constructor_If_Passed_Context_Is_Null_Must_Throw_Exception()
 {
     //
     // Arrange, Act, Assert
     //
     var repository = new GenericRepository<IModel>(null);
 }
开发者ID:Cheranga,项目名称:DAL,代码行数:7,代码来源:GenericRepositoryTest.cs

示例8: Index

        //
        // GET: /School/
        public ActionResult Index()
        {
            var schoolRepository = new GenericRepository(new SchoolContext());
            var students = schoolRepository.GetQuery<Student>();

            return View();
        }
开发者ID:bicijinlian,项目名称:repositoryMVC,代码行数:9,代码来源:SchoolController.cs

示例9: DeleteMovieWhenExistingItemShouldDelete

        public void DeleteMovieWhenExistingItemShouldDelete()
        {
            //Arrange -> prepare the objects
            var repo = new GenericRepository<Movie>(new MoviesGalleryContext());
            var movie = new Movie()
            {
                Id = 1,
                Length = 10,
                Ration = 10
            };

            //Act -> perform some logic
            repo.Add(movie);
            repo.SaveChanges();

            var movieFromDb = repo.GetById(movie.Id);

            repo.Delete(movieFromDb);
            repo.SaveChanges();

            var newMovieFromDb = repo.GetById(movie.Id);
            
            //Asssert -> expect and exception
            Assert.IsNull(newMovieFromDb);
        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:25,代码来源:RepositoeisTest.cs

示例10: Add

        public object Add(AddTripModel model)
        {
            GenericRepository<Trip> TripRepo = new GenericRepository<Trip>();
            GenericRepository<User> userRepo = new GenericRepository<User>();
             User user = userRepo.GetSingle(u => u.Username == User.Identity.Name);
            DateTime departDate;
            if (!DateTime.TryParse(model.Depdate, out departDate))
            {
                return false;
            }

            Trip Trip = new Trip()
            {
                UserId =user.UserId,
                DepartDate = departDate,
                AvailableSeatNumber = model.Seatnum,
                Price = model.Price,
                DepMin=model.Min,
                DepHour=model.Hour,
                EstimatedHour=model.EstHour,
                EstimatedMin=model.EstMin,
                DepartLocationId=model.DepLocId,
                ArrivalLocationId=model.ArrLocId,
                CarId = 1,

            };
            TripRepo.Add(Trip);
            return true;
        }
开发者ID:yigityesilpinar,项目名称:Web-Based-Application-of-Carpooling,代码行数:29,代码来源:TripController.cs

示例11: GetUserById

 public User GetUserById(int IdUser)
 {
     using (var repository = new GenericRepository())
     {
         return repository.ReadById<User>(IdUser);
     }
 }
开发者ID:jdnichollsc,项目名称:N-Tier,代码行数:7,代码来源:UserManager.cs

示例12: Main

        static void Main(string[] args)
        {
            var contactsRepository = new GenericRepository<Contact>();

            contactsRepository.Delete(5);

            //for (int i = 0; i < 1000; i++)
            //{
            //    var currentContact = new Contact();
            //    currentContact.FirstName = "ContactFirstName" + i;
            //    currentContact.LastName = "ContactLastName" + i;

            //    if (i % 3 == 0)
            //    {
            //        currentContact.Sex = Sex.Male;
            //        currentContact.Status = Status.Active;
            //    }
            //    else if (i % 3 == 1)
            //    {
            //        currentContact.Sex = Sex.Female;
            //        currentContact.Status = Status.Inactive;
            //    }
            //    else
            //    {
            //        currentContact.Sex = Sex.Other;
            //        currentContact.Status = Status.Deleted;
            //    }

            //    Random rand = new Random();
            //    currentContact.Telephone = rand.Next(1000000000, 2000000000).ToString();

            //    contactsRepository.Add(currentContact);
            //}
        }
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:34,代码来源:Program.cs

示例13: GetData

        public void GetData()
        {
            GenericRepository<t_loan_lead> loan = new GenericRepository<t_loan_lead>(new sherlockEntities());
            loan.GetAll();

            GenericRepository<t_life_lead> life = new GenericRepository<t_life_lead>(new sherlockEntities());
            life.GetAll();

            GenericRepository<t_asu_lead> asu = new GenericRepository<t_asu_lead>(new sherlockEntities());
            asu.GetAll();

            GenericRepository<t_debt_lead> debt = new GenericRepository<t_debt_lead>(new sherlockEntities());
            debt.GetAll();

            GenericRepository<t_equityrelease_lead> equityrelease = new GenericRepository<t_equityrelease_lead>(new sherlockEntities());
            equityrelease.GetAll();

            GenericRepository<t_logbookloan_lead> logbookloan = new GenericRepository<t_logbookloan_lead>(new sherlockEntities());
            logbookloan.GetAll();

            GenericRepository<t_mortgage_lead> mortgage = new GenericRepository<t_mortgage_lead>(new sherlockEntities());
            mortgage.GetAll();

            GenericRepository<t_pmi_lead> pmi = new GenericRepository<t_pmi_lead>(new sherlockEntities());
            pmi.GetAll();

            GenericRepository<t_ppi_lead> ppi = new GenericRepository<t_ppi_lead>(new sherlockEntities());
            ppi.GetAll();

            GenericRepository<t_sme_mi_lead> sme_mi = new GenericRepository<t_sme_mi_lead>(new sherlockEntities());
            sme_mi.GetAll();

            GenericRepository<t_solar_lead> solar = new GenericRepository<t_solar_lead>(new sherlockEntities());
            solar.GetAll();
        }
开发者ID:indrajitdan,项目名称:Sherlock,代码行数:35,代码来源:Class1.cs

示例14: Delete

 public void Delete()
 {
     IGenericRepository<SysUser> user = new GenericRepository<SysUser>();
     //user.Delete(4);
     if (user.Submit() == -1)
         Assert.Fail();
 }
开发者ID:taccisum,项目名称:ExerciseSpace,代码行数:7,代码来源:UnitTestCrud.cs

示例15: Main

        static void Main(string[] args)
        {
            var loadFile = File.ReadAllLines(@"c:\users\luiz.araujo\documents\visual studio 2015\Projects\FinancialDic\FinancialDic.Load\load.csv");

            _repository = new GenericRepository<Word>();

            var count = 0;

            foreach (var line in loadFile)
            {
                var words = line.Split(';');

                count ++;

                var word = new Word()
                {
                    Id = count,
                    Portuguese = words[0],
                    English = words[1]
                };

                _repository.AddOrUpdate(word);
            }

            Console.WriteLine("Fim");
        }
开发者ID:luizearaujo,项目名称:FinancialDic,代码行数:26,代码来源:Program.cs


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