public Person GetPerson(int id) { using (var context = new PeopleCarsContext(_connectionString)) { return(context.People.FirstOrDefault(p => p.Id == id)); } }
public void AddQuestion(Question question, IEnumerable <string> tags) { using var ctx = new PeopleCarsContext(_connectionString); ctx.Questions.Add(question); ctx.SaveChanges(); foreach (string tag in tags) { Tag t = GetTag(tag); int tagId; if (t == null) { tagId = AddTag(tag); } else { tagId = t.Id; } ctx.QuestionsTags.Add(new QuestionsTags { QuestionId = question.Id, TagId = tagId }); } ctx.SaveChanges(); }
public IEnumerable <Person> GetPeople() { using (var context = new PeopleCarsContext(_connectionString)) { return(context.People.Include(c => c.Cars).ToList()); } }
public IEnumerable <Person> GetPeopleWithNoCars() { using (var context = new PeopleCarsContext(_connectionString)) { return(context.People.Include(c => c.Cars).Where(p => p.Cars.Any(c => c.Make == "Lamborghini")).ToList()); } }
private Tag GetTag(string name) { using (var ctx = new PeopleCarsContext(_connectionString)) { return(ctx.Tags.FirstOrDefault(t => t.Name == name)); } }
public void AddCar(Car car) { using (var context = new PeopleCarsContext(_connectionString)) { context.Cars.Add(car); context.SaveChanges(); } }
public List <Question> GetQuestionsForTag(string name) { using var ctx = new PeopleCarsContext(_connectionString); return(ctx.Questions.Include(q => q.QuestionsTags) .ThenInclude(qt => qt.Tag) .Where(c => c.QuestionsTags.Any(t => t.Tag.Name == name)) .ToList()); }
public List <Person> GetPeopleWithNoCars() { using var context = new PeopleCarsContext(_connectionString); return(context.People.Include(p => p.Cars) .Where(p => p.Cars.Count == 0).ToList()); //return context.People.Include(c => c.Cars) // .Where(p => p.Cars.Any(c => c.Make == "Lamborghini")) // .ToList(); }
private int AddTag(string name) { using var ctx = new PeopleCarsContext(_connectionString); var tag = new Tag { Name = name }; ctx.Tags.Add(tag); ctx.SaveChanges(); return(tag.Id); }
public List <Person> GetPeople() { using var context = new PeopleCarsContext(_connectionString); return(context.People.Include(c => c.Cars).ToList()); }
public void AddPerson(Person person) { using var context = new PeopleCarsContext(_connectionString); context.People.Add(person); context.SaveChanges(); }