Exemplo n.º 1
0
 public static List <Contact> GetAllContactsFromDB()
 {
     using (AddressbookDB db = new AddressbookDB())
     {
         return((from c in db.Contacts.Where(x => x.Deprecated == "0000-00-00 00:00:00") select c).ToList());
     }
 }
 public List <Contact> GetGroupContactsFromDB()
 {
     using (AddressbookDB db = new AddressbookDB())
     {
         return((from c in db.Contacts
                 from groupContactRelation in db.GroupContactRelation.Where(p => p.GroupId == Id && p.ContactId == c.Id && c.Deprecated == "0000-00-00 00:00:00")
                 select c).Distinct().ToList());
     }
 }
        public static List <ContactGroup> GetAllGroupsFromDB()
        {
            // option 1 - opens a connection and closes at the end (the same can be used when working with files)
            using (AddressbookDB db = new AddressbookDB())
            {
                return((from g in db.Groups select g).ToList());
            }

            // option 2
            //AddressbookDB db = new AddressbookDB(); // to establish connection to the DB
            //List<ContactGroup> groupsFromDB = (from g in db.Groups select g).ToList(); // using LINQ
            //db.Close();
        }