示例#1
0
        private static void readRecords()
        {
            var context = new PhoneBookDataContext();
            var names   = from c in context.ContactTables
                          select c.ContactName;

            foreach (var name in names)
            {
                Console.WriteLine(name);
            }
        }
示例#2
0
        private static void deleteRecord()
        {
            var context  = new PhoneBookDataContext();
            var selected = (from c in context.ContactTables where c.ContactName == "Thompson" select c).FirstOrDefault();

            if (selected == null)
            {
                Console.WriteLine("No record is found");
                return;
            }
            context.ContactTables.DeleteOnSubmit(selected);
            context.SubmitChanges();
        }
示例#3
0
        private static void bulkinsertToDatabase()
        {
            //Read the data of the XML Document and insert all the xmldata into the table of our database.
            var context = new PhoneBookDataContext();//This class is autogenerated by the LINQ based on the name of the DBML File.
            var doc     = XDocument.Load("PhoneBook.xml");
            var data    = from element in doc.Descendants("Contact")
                          select new ContactTable
            {
                PhoneNo     = Convert.ToInt64(element.Element("PhoneNo").Value),
                ContactName = element.Element("Name").Value,
                City        = element.Element("City").Value
            };

            context.ContactTables.InsertAllOnSubmit(data); //Bulk Adding to the contacttables collection
            context.SubmitChanges();                       //Commit..
        }