static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; Defect defect = context.Defects .Where(d => d.ID==1) .Single(); User tim = defect.CreatedBy; defect.AssignedTo = tim; tim.Name = "Timothy Trotter"; defect.Status = Status.Fixed; defect.LastModified = SampleData.May(31); context.SubmitChanges(); } using (var context = new DefectModelDataContext()) { Defect d = (from defect in context.Defects where defect.ID==1 select defect).Single(); Console.WriteLine (d); } }
static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; context.DeleteDatabase(); context.CreateDatabase(); } }
static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; context.NotificationSubscriptions.DeleteAllOnSubmit(from subscription in context.NotificationSubscriptions select subscription); context.Projects.DeleteAllOnSubmit(from project in context.Projects select project); context.Defects.DeleteAllOnSubmit(from defect in context.Defects select defect); context.Users.DeleteAllOnSubmit(from user in context.Users select user); context.SubmitChanges(); } }
static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; context.Defects.InsertAllOnSubmit(SampleData.AllDefects); context.NotificationSubscriptions.InsertAllOnSubmit(SampleData.AllSubscriptions); context.Users.InsertAllOnSubmit(SampleData.AllUsers); context.Projects.InsertAllOnSubmit(SampleData.AllProjects); context.SubmitChanges(); } }
static void Main() { using (var context = new DefectModelDataContext()) { var query = from defect in context.Defects where defect.Status == Status.Closed select defect; foreach (var defect in query) { Console.WriteLine(defect); } } }
static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; Console.WriteLine("Loading defect"); var defect = (from bug in context.Defects where bug.Summary.Contains("Welsh") select bug).Single(); Console.WriteLine("Using Project property..."); Console.WriteLine("Project={0}", defect.Project.Name); } }
static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; var query = from defect in context.Defects select new { defect.Summary, ProjectName=defect.Project.Name }; foreach (var entry in query) { Console.WriteLine("{0}: {1}", entry.ProjectName, entry.Summary); } } }
static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; var query = from user in context.Users let length = user.Name.Length orderby length select new { Name = user.Name, Length = length }; foreach (var entry in query) { Console.WriteLine("{0}: {1}", entry.Length, entry.Name); } } }
static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; var query = from defect in context.Defects join subscription in context.NotificationSubscriptions on defect.Project equals subscription.Project select new { defect.Summary, subscription.EmailAddress }; foreach (var entry in query) { Console.WriteLine("{0}: {1}", entry.EmailAddress, entry.Summary); } } }
static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; // Delete the contents of the tables context.ExecuteCommand("DELETE FROM Defect"); context.ExecuteCommand("DELETE FROM NotificationSubscription"); context.ExecuteCommand("DELETE FROM Project"); context.ExecuteCommand("DELETE FROM DefectUser"); // Reset the identity columns context.ExecuteCommand("DBCC CHECKIDENT('Defect', RESEED, 0)"); context.ExecuteCommand("DBCC CHECKIDENT('NotificationSubscription', RESEED, 0)"); context.ExecuteCommand("DBCC CHECKIDENT('Project', RESEED, 0)"); context.ExecuteCommand("DBCC CHECKIDENT('DefectUser', RESEED, 0)"); } }
static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; User tim = (from user in context.Users where user.Name=="Tim Trotter" select user).Single(); var query = from defect in context.Defects where defect.Status != Status.Closed where defect.AssignedTo == tim select defect.Summary; foreach (var summary in query) { Console.WriteLine(summary); } } }
static void Main() { using (var context = new DefectModelDataContext()) { context.Log = Console.Out; var query = from defect in context.Defects join subscription in context.NotificationSubscriptions on defect.Project equals subscription.Project into groupedSubscriptions select new { Defect = defect, Subscriptions = groupedSubscriptions }; foreach (var entry in query) { Console.WriteLine(entry.Defect.Summary); Console.WriteLine(entry.Subscriptions.Count()); foreach (var subscription in entry.Subscriptions) { Console.WriteLine(" {0}", subscription.EmailAddress); } } } }