public void LoadFirst() { Contacts.Clear(); Phones.Clear(); string connString = @"Data Source=.\SQLEXPRESS; Initial Catalog=PhoneContacts; Integrated Security=True;"; SqlConnection con = new SqlConnection(connString); string sqlQueryString = "SELECT * from Contacts "; SqlCommand cmd = new SqlCommand(sqlQueryString, con); con.Open(); SqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { Contacts.Add(new Contact { Id = (int)dataReader["id"], Email = dataReader["Email"] as string, Name = dataReader["Name"] as string, LastName = dataReader["LastName"] as string, SecondName = dataReader["SecondName"] as string, ImageBytes = dataReader["Image"] as byte[], Bithday = dataReader["Bithday"] as string }); } con.Close(); }
public void LoadContacts(int idCon) { Contacts.Clear(); Phones.Clear(); string connString = @"Data Source=.\SQLEXPRESS; Initial Catalog=PhoneContacts; Integrated Security=True;"; SqlConnection con = new SqlConnection(connString); string sqlQueryString2 = "Select * From Numbers "; SqlCommand cmd2 = new SqlCommand(sqlQueryString2, con); con.Open(); SqlDataReader datareader1 = cmd2.ExecuteReader(); while (datareader1.Read()) { Phones.Add(new Phone { Contact_id = (int)datareader1["Contact_id"], Number = datareader1["Phone"] as string, Type = (PhoneType)datareader1["Type_id"] }); } con.Close(); string sqlQueryString = "SELECT* from Contacts "; SqlCommand cmd = new SqlCommand(sqlQueryString, con); con.Open(); SqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { Contacts.Add(new Contact { Id = (int)dataReader["id"], Email = dataReader["Email"] as string, Name = dataReader["Name"] as string, LastName = dataReader["LastName"] as string, SecondName = dataReader["SecondName"] as string, ImageBytes = dataReader["Image"] as byte[], Bithday = dataReader["Bithday"] as string, Numbers = Phones.FindAll(Phone => Phone.Contact_id == idCon) }); } con.Close(); }
protected virtual void ClearNavigationProperties() { Phones.Clear(); }