static void Main() { Database.SetInitializer( new MigrateDatabaseToLatestVersion<StudentsDbContext, Configuration>()); using (var context = new StudentsDbContext()) { var peshoStudent = new Student { FirstName = "Pesho", LastName = "Telerikov", Email = "*****@*****.**" }; context.Students.Add(peshoStudent); affectedRows = context.SaveChanges(); var someGuyOrGal = context.Students.Find(200); if (someGuyOrGal != null) { Console.WriteLine(someGuyOrGal.ToString()); } } Console.WriteLine("Completed! Affected Rows: {0}", affectedRows); }
private static List<Student> GenerateStudents() { List<Student> students = new List<Student>(); var number = new Random(); var subjects = new string[] { "Math", "IT", "Economics", "Pista" }; for (int i = 0; i < 10; i++) { Student currentStudent = new Student { Id = i, FirstName = "Pesho"+i, Lastname = "Stroshenkov"+i, Age = i+number.Next(18,20), Grade = number.Next(1,13), }; for (int j = 0; j < subjects.Length; j++) { currentStudent.Marks.Add ( new Mark { Subject = subjects[j], Score = number.Next(2,7) }); } students.Add(currentStudent); } return students; }
public DataSeeder() { this.Students = new List<Student>(); this.Courses = new List<Course>(); this.Homeworks = new List<Homework>(); this.randomGenerator = new Random(); for (int i = 0; i < 100; i++) { var deadLine = new Homework() { Content = this.GetRandomName(), DeadLine = this.GerRandomDate() }; this.Homeworks.Add(deadLine); } for (int i = 0; i < 100; i++) { var student = new Student() { Name = this.GetRandomName(), StudentId = GetRandomNumberInRange(0, 10), HomeWorks = this.Homeworks.Take(10).ToList()}; this.Students.Add(student); } for (int i = 0; i < 100; i++) { var course = new Course() { Name = this.GetRandomName(), Description = this.GetRandomName(), Materials = this.GetRandomName(), Homeworks = this.Homeworks.Take(100).ToList(),Students=this.Students.Take(1).ToList()}; this.Courses.Add(course); } }
static void Main(string[] args) { SchoolSystemContext context = new SchoolSystemContext(); Student sampleStudent = new Student(); sampleStudent.Name = "Name2"; context.Students.Add(sampleStudent); context.SaveChanges(); }
static void Main(string[] args) { var db = new ApplicationDbContext(); db.Database.Initialize(true); PrintStudents(db); var rnd = new Random(); using (db) { for (int i = 0; i < 20; i++) { var newStudent = new Student() { Name = "Mitko" + i, StdentNumber = rnd.Next(100000, 999999) }; db.Students.Add(newStudent); } db.SaveChanges(); } }
public IHttpActionResult Post(StudentModel model) { if (!this.ModelState.IsValid) { return this.BadRequest("Incorrect data"); } var student = new Student { FirstName = model.FirstName, LastName = model.LastName, StudentInfo = { Address = model.Address, Email = model.Email } }; this.Data.Students.Add(student); this.Data.SaveChanges(); return this.Ok("Record added"); }