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


C# IDbConnection.GetList方法代码示例

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


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

示例1: About

        public ActionResult About()
        {
            _connection = Connect.Open();

            var data = _connection.GetList<Student>();

            //var result = from student in data
            //             group student by student.EnrollmentDate
            //    into dateGroup
            //             select new EnrollmentDateGroup
            //             {
            //                 EnrollmentDate = dateGroup.Key,
            //                 StudentCount = dateGroup.Count()
            //             };

            var result = data.GroupBy(s => s.EnrollmentDate)
                .Select(x => new EnrollmentDateGroup
                {
                    EnrollmentDate = x.Key,
                    StudentCount = x.Count()

                });

            return View(result);
        }
开发者ID:armory09,项目名称:ConstosoUniversityMVCwithDapper,代码行数:25,代码来源:HomeController.cs

示例2: Index

        // GET: Student
        public ActionResult Index(string sortOrder, string curentFilter, string searchString, int? page)
        {
            ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = curentFilter;
            }
            ViewBag.CurrentFilter = searchString;

            _connection = Connect.Open();
            var studentLst = _connection.GetList<Student>();

            if (!string.IsNullOrEmpty(searchString))
            {
                studentLst =
                    studentLst.ToList()
                        .Where(s => s.Lastname.ToLower().Contains(searchString.ToLower()) || s.FirstMidName.ToLower().Contains(searchString.ToLower()));
            }

            switch (sortOrder)
            {
                case "name_desc":
                    studentLst = studentLst.OrderByDescending(s => s.Lastname);
                    break;
                case "Date":
                    studentLst = studentLst.OrderBy(s => s.EnrollmentDate);
                    break;

                case "date_desc":
                    studentLst = studentLst.OrderByDescending(s => s.EnrollmentDate);
                    break;

                default:
                    studentLst = studentLst.OrderBy(s => s.Lastname);
                    break;
            }
            const int pageSize = 5;
            var pageNumber = (page ?? 1);

            return View(studentLst.ToPagedList(pageNumber, pageSize));
        }
开发者ID:armory09,项目名称:ConstosoUniversityMVCwithDapper,代码行数:48,代码来源:StudentController.cs

示例3: PopulateInstructorDepartmentList

 private void PopulateInstructorDepartmentList(object selectedInstructor = null)
 {
     _conection = Connect.Open();
     var instructorQuery = _conection.GetList<Instructor>().OrderBy(s => s.LastName).Select(s => s);
     ViewBag.InstructorId = new SelectList(instructorQuery, "InstructorId", "FullName", selectedInstructor);
 }
开发者ID:armory09,项目名称:ConstosoUniversityMVCwithDapper,代码行数:6,代码来源:DepartmentController.cs

示例4: Delete

 public ActionResult Delete(int id)
 {
     try
     {
         _connection = Connect.Open();
         var courseInstuctor = _connection.GetList<CourseInstructor>(id);
         foreach (var course in courseInstuctor)
         {
             var condition = new PredicateGroup {Operator = GroupOperator.And, Predicates = new List<IPredicate>()};
             condition.Predicates.Add(Predicates.Field<CourseInstructor>(s=>s.CourseId, Operator.Eq, course.CourseId));
             condition.Predicates.Add(Predicates.Field<CourseInstructor>(s=>s.InstructorId, Operator.Eq, id));
             _connection.Delete<CourseInstructor>(condition);
         }
         _connection.Delete<OfficeAssignment>(Predicates.Field<OfficeAssignment>(s => s.InstructorId, Operator.Eq, id));
         _connection.Delete<Instructor>(Predicates.Field<Instructor>(s => s.InstructorId, Operator.Eq, id));
     }
     catch(DataException)
     {
         return RedirectToAction("Delete", new {id, saveChangesError = true});
     }
     return RedirectToAction("Index");
 }
开发者ID:armory09,项目名称:ConstosoUniversityMVCwithDapper,代码行数:22,代码来源:InstructorController.cs

示例5: Main

        static void Main(string[] args)
        {
            _connection = Connect.Open();

            var instructorsLst = _connection.GetList<Instructor>();

            var departments = new List<Department>
            {
                new Department
                {
                    Name = "English", Budget = 350000,
                    StartDate = DateTime.Parse("2007-09-01"),
                    InstructorId = instructorsLst.Single(i=>i.LastName == "Abercrombie").InstructorId
                },
                new Department
                {
                    Name = "Mathematics", Budget = 100000,
                    StartDate = DateTime.Parse("2007-09-01"),
                    InstructorId = instructorsLst.Single(s=>s.LastName == "Fakhouri").InstructorId
                }                                         ,
                new Department
                {
                    Name = "Engineering", Budget = 350000,
                    StartDate = DateTime.Parse("2007-09-01"),
                    InstructorId = instructorsLst.Single(s=>s.LastName == "Harui").InstructorId
                }                                                                              ,
                new Department
                {
                    Name = "Economics", Budget = 100000,
                    StartDate = DateTime.Parse("2007-09-01"),
                    InstructorId = instructorsLst.Single(s=>s.LastName == "Kapoor").InstructorId
                }
            };

            _connection.Insert<Department>(departments);
            var departmentLst = _connection.GetList<Department>();

            var courses = new List<Course>
            {
                new Course
                {
                    CourseId = 1050, Title = "Chemistry", Credits = 3,
                    DepartmentId = departmentLst.Single(s=>s.Name == "Engineering").DepartmentId
                },
                new Course
                {
                    CourseId = 4022, Title = "Microeconomics", Credits = 3,
                    DepartmentId = departmentLst.Single(s=>s.Name == "Economics").DepartmentId
                }                                                                           ,
                new Course
                {
                    CourseId = 4041, Title = "Macroeconomics", Credits = 3,
                    DepartmentId = departmentLst.Single(s=>s.Name == "Economics").DepartmentId
                }                                                                           ,
                new Course
                {
                    CourseId = 1045, Title = "Calculus", Credits = 4,
                    DepartmentId = departmentLst.Single(s=>s.Name == "Mathematics").DepartmentId
                }                                                                             ,
                new Course
                {
                    CourseId = 3141, Title = "Trigonometry", Credits = 4,
                    DepartmentId = departmentLst.Single(s=>s.Name == "Mathematics").DepartmentId
                }                                                                             ,
                new Course
                {
                    CourseId = 2021, Title = "Composition", Credits = 3,
                    DepartmentId = departmentLst.Single(s=>s.Name == "English").DepartmentId
                }                                                                         ,
                new Course
                {
                    CourseId = 2042, Title = "Literature", Credits = 4,
                    DepartmentId = departmentLst.Single(s=>s.Name == "English").DepartmentId
                }
            };
            _connection.Insert<Course>(courses);

            var officeAssignment = new List<OfficeAssignment>
            {
                new OfficeAssignment
                {
                    InstructorId = instructorsLst.Single(s=>s.LastName == "Fakhouri").InstructorId,
                    Location = "Smith 17"
                }                       ,
                new OfficeAssignment
                {
                    InstructorId = instructorsLst.Single(s=>s.LastName == "Harui").InstructorId,
                    Location = "Gowan 17"
                }                        ,
                new OfficeAssignment
                {
                    InstructorId = instructorsLst.Single(s=>s.LastName == "Kapoor").InstructorId,
                    Location = "Thompson 304"
                }
            };

            _connection.Insert<OfficeAssignment>(officeAssignment);

            var studentLst = _connection.GetList<Student>();

//.........这里部分代码省略.........
开发者ID:armory09,项目名称:ConstosoUniversityMVCwithDapper,代码行数:101,代码来源:Program.cs


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