protected Person(string firstName, string lastName, Hometown hometown) { FirstName = firstName; LastName = lastName; Hometown = hometown; _regex = new Regex(_pattern); }
/* * Comprehension Queries * https://learning.oreilly.com/library/view/linq-pocket-reference/9780596519247/ch01s03.html * * C# provides a syntatic shortcut for writing LINQ queries, called query comprehension syntax, * or simply query syntax. * * A comprehnsion query always starts with a 'from' clause and end with either a 'select or group' * clause. The 'from' clause declares an iteration variable. The compiler processes comprehension * queries by translating them to lambda syntax this is similar to what it does to the 'foreach' statements * translating them into calls to GetEnumerator and MoveNext. This means anything you can write in * comprehension syntax you can also write in lambda syntax. */ private static void LQComprehensionQuery() { var employeeByState = from e in Employ.GetAllEmploy() join h in Hometown.GetHometown() on new { City = e.City, State = e.State } equals new { City = h.City, State = h.State } select new { e.LastName, h.CityCode }; foreach (var employee in employeeByState) { Console.WriteLine(employee.LastName + ", " + employee.CityCode); } } // End LQComprehensionQuery
static void Main(string[] args) { var db = new PersonContext(); // SELECT * FROM People var allPeople = db.People.ToList(); // CREATE! var person = new Person { FullName = "Jerry", HairColor = "Bald", IsRightHanded = true, Height = 72, Age = 53 }; db.People.Add(person); db.SaveChanges(); // READ var people = db.People.ToList(); // SELECT * FROM People WHERE Age < 12 var youngins = db.People.Where(peep => peep.Age < 12); // SELECT FullName FROM People // WHERE HairColor = "Bald" && IsRightHanded = False var baldLefthandedPeopleNames = db.People .Where(w => !w.IsRightHanded && w.HairColor == "Bald") .Select(s => s.FullName); // UPDATING // SELECT TOP(1) * FROM PEOPLE WHERE FullName == "Jerry" // IN C#: using the reader, create a Person Object var jerry = db.People.First(f => f.FullName == "Jerry"); // change the desired values jerry.HairColor = "Brown"; // UPDATE PEOPLE SET (HairColor = "Brown") WHERE Id = Jerry.Id db.SaveChanges(); var cities = db.Cities.ToList(); var newYork = new Hometown { Name = "New York", Population = 12000000, State = "NY" }; db.Cities.Add(newYork); db.SaveChanges(); jerry.HomeTown = newYork; db.SaveChanges(); var otherJerry = db.People.First(f => f.FullName == "Jerry"); db.People.Remove(otherJerry); }
public Developer(string firstName, string lastName, Hometown hometown, EmployeeClassification classification, Seniority seniorityLevel) : base(firstName, lastName, hometown, classification) { SeniorityLevel = seniorityLevel; }
protected Employee(string firstName, string lastName, Hometown hometown, EmployeeClassification classification) : base(firstName, lastName, hometown) { Classification = classification; }