internal static void Main(string[] args) { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); using (var db = new StudentSystemContext()) { var material = new Material { Content = "za sega njama" }; db.Materials.Add(material); var course = new Course { Name = "Algorihms", Description = "gadno" }; course.Materials.Add(material); db.Courses.Add(course); var student = new Student { Name = "Pesho", Number = 10000 }; student.Cources.Add(course); db.Students.Add(student); db.SaveChanges(); } }
private static void Main(string[] args) { var db = new StudentSystemContext(); using (db) { db.Courses.Add( new Course { Description = "C# course", Students = new List<Student>() { new Student { Name = "Pencho", Number = 13 } } }); db.SaveChanges(); var students = db.Students.Select(x => new { x.Name, x.Courses }); foreach (var student in students) { Console.WriteLine(student.Name + " participates in " + string.Join(",", student.Courses.Select(x => x.Description))); } } }
static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); var db = new StudentSystemContext(); using (db) { var homework = new Homework(); var student = new Student(); var course = new Course(); student.FirstName = "Gancho"; student.LastName = "Minchev"; student.StudentNumber = 12345; course.Name = "Animals"; course.Students.Add(student); course.Homeworks.Add(homework); course.Materials = "Books"; course.Students.Add(student); homework.Content = "African Animals"; homework.Course = course; student.Homeworks.Add(homework); db.SaveChanges(); } }
static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); var db = new StudentSystemContext(); db.SaveChanges(); }
static void Main() { //Database.SetInitializer(new DropCreateDatabaseAlways<StudentSystemContext>()); Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); StudentSystemContext dbContext = new StudentSystemContext(); var student = new Student() { Name = "Gosho", Number = "15", Courses = new HashSet<Course>() { new Course() { Name = "Entity Framework", Description = "Entity Framework Entity Framework Entity Framework Entity Framework ", Material = "Data base miracles Data base miracles Data base miracles", } }, }; dbContext.Students.Add(student); Console.WriteLine("Student added."); //var students = dbContext.Students.Where(s => s.Name == "Pesho"); //Console.WriteLine(student.Name); dbContext.SaveChanges(); }
/* 02. Write a console application that uses the data.*/ /// <summary> /// Mains this instanse. /// </summary> public static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); using (var db = new StudentSystemContext()) { var pesho = new Student { Name = "Pesho", Number = 666 }; db.Students.Add(pesho); db.SaveChanges(); var dbCourse = new Course { Name = "Database Course", Description = "Basic Database operations", Materials = "http://telerikacademy.com/Courses/Courses/Details/98" }; db.Courses.Add(dbCourse); db.SaveChanges(); var course = db.Courses.First(c => c.Name == dbCourse.Name); var student = db.Students.First(s => s.Number == pesho.Number); var hw = new Homework { Content = "Empty Homework", TimeSent = DateTime.Now, CourseId = course.CourseId, StudentId = student.StudentID }; db.Homeworks.Add(hw); db.SaveChanges(); } ListStudents(); }
private static void PrintStudents(StudentSystemContext studentSystemContext) { Console.WriteLine("Students: "); foreach (var students in studentSystemContext.Students.Include("Courses")) { Console.WriteLine(" - {0} -> present in {1} course(s).", students.Name, students.Courses.Count()); } }
private static void PrintCourses(StudentSystemContext studentSystemContext) { Console.WriteLine("\nCourses: "); foreach (var course in studentSystemContext.Courses.Include("Homeworks")) { Console.WriteLine(" - {0} -> has {1} homework(s).", course.Description, course.Homeworks.Count()); } }
static void Main() { Database.SetInitializer( new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); var db = new StudentSystemContext(); db.Students.Add(new Student { Name = "gosho", Number = "123456" }); db.SaveChanges(); }
private static void Main() { var studentSystemContext = new StudentSystemContext(); studentSystemContext.Database.Initialize(true); PrintStudents(studentSystemContext); PrintCourses(studentSystemContext); }
static void Main() { var context = new StudentSystemContext(); //This is to create the data base Problem01 int count = context.Students.; Console.WriteLine(count); //Fill created database Problem 02 //var student = new Student() //{ // Id = 1, // Name = "Dimitar Stoyanov", // PhoneNumber = "+359 123 231 491", // RegstrationDate = DateTime.Now, //}; //var resource = new Resource() //{ // Name = "C# Data Structures - Liner Data", // ResourceType = ResourceType.Video, // URL = "https://softuni.bg/trainings/1147/Data-Structures-June-2015" //}; //var homework = new Homework() //{ // Content = "Linear Data Structures – Stacks and Queues", // ContentType = ContentType.zip, // SubmissionDate = new DateTime(2016, 01, 12) //}; //var course = new Course() //{ // Name = "Maths", // Description = "Algebra", // StartDate = new DateTime(2015, 7, 12), // EndDate = new DateTime(2015, 8, 15), // Price = 200 //}; //course.Students.Add(student); //course.Homeworks.Add(homework); //course.Resources.Add(resource); //student.Courses.Add(course); //student.Homeworks.Add(homework); //context.Resources.Add(resource); //context.Homeworks.Add(homework); //context.Courses.Add(course); //context.Students.Add(student); //context.SaveChanges(); }
static void Main(string[] args) { Database.SetInitializer( new MigrateDatabaseToLatestVersion<StudentSystemContext, Data.Migrations.Configuration>()); StudentSystemContext context = new StudentSystemContext(); context.Students.Add(new Student() {FirstName = "Test",LastName = "Student"}); context.SaveChanges(); }
private static void ListAllStudents(StudentSystemContext context) { foreach (var student in context.Students.Include("Courses")) { Console.WriteLine( "Student: {0}; FacultyNumber: {1}; Courses: {2}", student.Name, student.FacultyNumber, string.Join(", ", student.Courses.Select(x => x.Name))); } }
private static void ListAllCourses(StudentSystemContext context) { foreach (var course in context.Courses.Include("Students")) { Console.WriteLine( "Course: {0}; Description: {1}; Courses: {2}", course.Name, course.Description, string.Join(", ", course.Students.Select(x => x.Name))); } }
/// <summary> /// List all students. /// </summary> private static void ListStudents() { using (var db = new StudentSystemContext()) { var students = db.Students; foreach (var student in students) { Console.WriteLine("Name: {0}, Number: {1}", student.Name, student.Number); } } }
public static void thirdQuery() { var context = new StudentSystemContext(); var courses = context.Courses .Where(c => c.Resources.Count > 6) .OrderByDescending(c => c.Resources.Count) .ThenByDescending(c => c.StartDate) .Select(c => new { c.Name, c.Resources.Count }); }
static void Main(string[] args) { var dataBase = new StudentSystemContext(); var course = new Courses { Parent = null, Name = "Database course", Description = "A course that all junior develepers need to pass", Materials = "Google.com"}; dataBase.Courses.Add(course); var studentOnDataBaseCourse = new Students { Name = "Bill Gates", Number = 1 }; var homeWorkForDataBases = new Homework { Content = "Introduction in SQL" }; dataBase.SaveChanges(); }
public static void Main() { // IMPORTANT: Change connection string in "StudentSystem.Data/ConnectionStrings.settings" Console.Write("Loading..."); var forumSystemContext = new StudentSystemContext(); forumSystemContext.Database.Initialize(true); PrintStudents(forumSystemContext); PrintCourses(forumSystemContext); PrintHomeworks(forumSystemContext); }
public static void secondQuery() { var context = new StudentSystemContext(); var courses = context.Courses .OrderBy(c => c.StartDate) .ThenByDescending(c => c.EndDate) .Select(c => new { c.Name, c.Description, c.Resources }); }
public static void firstQuery() { var context = new StudentSystemContext(); var students = context.Students.Select(s => new { s.Name, Homeworks = s.Homeworks.Select(h => new { h.Content, h.HomeworkContentType }) }); }
static void Main() { Database.SetInitializer( new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); using (StudentSystemContext dbContext = new StudentSystemContext()) { foreach (Student student in dbContext.Students) { Console.WriteLine("{0} {1} - {2}", student.FirstName, student.LastName, student.FacultyNumber); } } }
public static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); var dbContext = new StudentSystemContext(); // Force Initialization. dbContext.Database.Initialize(true); Console.WriteLine("All Students:"); ListAllStudents(dbContext); Console.WriteLine("All Courses:"); ListAllCourses(dbContext); }
private static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); using (var studentSystem = new StudentSystemContext()) { studentSystem.Students.Add(new Student() { Name = "Svetlin Nakov", Number = 5000981 }); studentSystem.SaveChanges(); } }
public static void fifthQuery() { var context = new StudentSystemContext(); var students = context.Students .OrderByDescending(s => s.Courseses.Sum(c => c.Price)) .ThenByDescending(s => s.Courseses.Count) .ThenBy(s => s.Name) .Select(s => new { s.Name, s.Courseses.Count, Price = s.Courseses.Sum(c => c.Price), AveragePrice = s.Courseses.Average(c => c.Price) }); }
static void Main(string[] args) { var context = new StudentSystemContext(); //var count = context.Courses.Count(); //Console.WriteLine(count); //var migrationStrategy = new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>(); //migrationStrategy.InitializeDatabase(context); }
private static void PrintHomeworks(StudentSystemContext forumSystemContext) { Console.WriteLine("\nHomeworks: "); foreach (var homework in forumSystemContext.Homeworks.Include("Materials").Where(h => !h.StudentId.HasValue)) { Console.WriteLine(" - {0} ({1}) -> has {2} material(s).", homework.Content, homework.Course.Description, homework.Materials.Count()); foreach (var material in homework.Materials) { Console.WriteLine(" - {0} ({2}) - {1}", material.Type, material.DownloadUrl, material.Homework.Content); } Console.WriteLine(); } }
public static void fourthQuery() { var context = new StudentSystemContext(); var courseDate = new DateTime(2011, 06, 12); var courses = context.Courses .Where(c => c.StartDate <= courseDate && c.EndDate >= courseDate) .OrderByDescending(c => c.Students.Count) .ThenByDescending(c => (c.EndDate - c.StartDate).Days) .Select(c => new { c.Name, c.StartDate, c.EndDate, CourseDuration = (c.EndDate - c.StartDate).Days, c.Students.Count }); }
public object GetService(Type serviceType) { if (serviceType == typeof(StudentsController)) { DbContext context = new StudentSystemContext(); var studentRepository = new EfRepository<Student>(context); var schoolRepository = new EfRepository<School>(context); var markRepository = new EfRepository<Mark>(context); return new StudentsController(studentRepository, schoolRepository, markRepository); } else if (serviceType == typeof(SchoolsController)) { DbContext context = new StudentSystemContext(); var schoolRepository = new EfRepository<School>(context); var studentRepository = new EfRepository<Student>(context); return new SchoolsController(schoolRepository, studentRepository); } else { return null; } }
static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentSystemContext, Configuration>()); var context = new StudentSystemContext(); var course = new Course { Name = "Database" }; var student = new Student { StudentNumber = 31150 }; student.Name = "Pesho Petrov"; course.Students.Add(student); student.Courses.Add(course); var homework = new Homework { SendDate = DateTime.Now, CourseId = 1, StudentId = 1 }; var lecture = new Material { CourseId = 1 }; student.Homeworks.Add(homework); course.Materials.Add(lecture); course.Homeworks.Add(homework); context.Courses.Add(course); context.Students.Add(student); context.Homeworks.Add(homework); context.Materials.Add(lecture); context.SaveChanges(); }
public static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); Random randomGen = new Random(); using (var dbContext = new StudentSystemContext()) { for (int i = 0; i < 20; i++) { Student student1 = new Student() { Name = "Ivan" + i, StudentNumber = randomGen.Next(100000, 999999) }; dbContext.Students.Add(student1); } dbContext.SaveChanges(); } }
public DetailsModel(StudentSystem.Data.StudentSystemContext context) { _context = context; }
public DeleteModel(StudentSystem.Data.StudentSystemContext context) { _context = context; }