Exemple #1
0
        static void CopyToDatabase(KULContext context)
        {
            Repository repo = new Repository();

            context.Groups.AddRange(repo.Groups);
            context.Students.AddRange(repo.Students);

            context.SaveChanges();
        }
Exemple #2
0
        static void FilterAndOrder(KULContext context)
        {
            var result = from s in context.Students
                         where s.BirthDate.Year >= 1999
                         orderby s.Rating descending, s.Name
            select s;

            foreach (var s in result)
            {
                Console.WriteLine("{0} {1}: {2}", s.Name, s.Surname, s.Rating);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            using (KULContext c = new KULContext())
            {
                // Uncomment and run once to fill the database
                // CopyToDatabase(c);

                // Queries
                //FilterAndOrder(c);
                //GroupByFirstLetter(c);
                Join(c);
            }
            Console.ReadKey();
        }
Exemple #4
0
        static void GroupByFirstLetter(KULContext context)
        {
            var result = from s in context.Students
                         group s by s.Name.Substring(0, 1) into g
                         select g;

            foreach (var group in result)
            {
                Console.WriteLine("\nFirst letter: {0}", group.Key);
                foreach (var s in group)
                {
                    Console.WriteLine("{0} {1}", s.Name, s.Surname);
                }
            }
        }
Exemple #5
0
        static void Join(KULContext context)
        {
            var result = from s in context.Students
                         join g in context.Groups
                         on s.GroupId equals g.Id
                         select new StudentViewModel
            {
                FullName  = s.Name + " " + s.Surname,
                Rating    = s.Rating,
                GroupName = g.Name
            };

            foreach (var s in result)
            {
                Console.WriteLine("{0} ({1}): rating = {2}", s.FullName, s.GroupName, s.Rating);
            }
        }