public void RandomMiddle() { middle_name tempMiddle = new middle_name(); if (this.MiddleName == null) { tempMiddle.MiddleID = -1; } else { tempMiddle = this.MiddleName; } middle_name newMiddle = new middle_name(); using (var context = new NameGeneratorContext()) { var nameQuery = context.middle_name .Where(n => n.Active != false) .ToList(); nameQuery.Shuffle(); foreach (middle_name qName in nameQuery) { newMiddle = qName; if (newMiddle.MiddleID != tempMiddle.MiddleID) { this.MiddleName = newMiddle; break; } } } }
public void NewMiddle() { middle_name tempMiddle = new middle_name(); if (this.MiddleName == null) { tempMiddle.MiddleID = -1; } else { tempMiddle = this.MiddleName; } middle_name newMiddle = new middle_name(); using (var context = new NameGeneratorContext()) { var nameQuery = context.middle_name .Where(n => n.Active != false) .ToList(); nameQuery.Shuffle(); foreach (middle_name qName in nameQuery) { newMiddle = qName; var fullQuery = context.full_name .Where(n => n.MiddleID == newMiddle.MiddleID) .Where(n => n.FirstID == this.FirstName.FirstID) .FirstOrDefault(); if (fullQuery == null && newMiddle.MiddleID != tempMiddle.MiddleID) { this.MiddleName = newMiddle; break; } } } if (this.MiddleName.MiddleID == tempMiddle.MiddleID) { System.Windows.Forms.MessageBox.Show("All valid combinations with the current first name have been tried. Please select a new first name"); this.RandomFirst(); } }