private static void ImportData(SpDataContext spContext, bool clear) { if (clear) { //delete all items. while (spContext.List <Department>().Take(100).DeleteAll()) { spContext.SaveChanges(); } while (spContext.List <Employee>().Take(100).DeleteAll()) { spContext.SaveChanges(); } } //var dep = spContext.List<Department>().GetEntries().First().Entity; //dep.Title = "Warner Brothers"; var department = spContext.List <Department>().AddOrUpdate(new Department() { Title = "Warner Brothers", ShortName = "WB" }, 1, true); spContext.SaveChanges(); //department = spContext.List<Department>().AddOrUpdate(dep); //spContext.SaveChanges(); var manager = spContext.List <Employee>().AddOrUpdate(new Employee() { FirstName = "Emma", LastName = "Stone", Phone = "8-1111-999", Email = "*****@*****.**", Position = EmployeePosition.Manager | EmployeePosition.Specialist }, 1, true); // save lookups spContext.SaveChanges(); var specialist = new Employee() { FirstName = "Will", LastName = "Smith", Phone = "7-1143-222", Email = "*****@*****.**", Position = EmployeePosition.Specialist }; specialist.DepartmentLookup.SetEntity(department.Entity); specialist.ManagerLookup.SetEntities(new[] { manager.Entity }); var entry = spContext.List <Employee>().AddOrUpdate(specialist, 2, true, true); spContext.SaveChanges(); }
static void Main(string[] args) { string siteUrl = ConfigurationManager.AppSettings["siteUrl"]; while (string.IsNullOrWhiteSpace(siteUrl)) { Console.WriteLine("Enter Site Url: "); siteUrl = Console.ReadLine(); } string userLogin = ConfigurationManager.AppSettings["userLogin"]; while (string.IsNullOrWhiteSpace(userLogin)) { Console.WriteLine("Enter User Login: "******"userPassword"]; using (var ctx = new SpDataContext(siteUrl)) { var clientContext = ctx.Context; clientContext.Credentials = new SharePointOnlineCredentials(userLogin, string.IsNullOrWhiteSpace(userPassword) ? GetPassword() : ConvertToSecureString(userPassword)); Deploy(ctx); ImportData(ctx, false); var departments = ctx.List <Department>().ToArray(); var employees = departments.First().Employees.ToArray(); if (!employees.Any()) { employees = ctx.List <Employee>().ToArray(); } var managers = employees.First().Managers.ToArray(); Debugger.Break(); Console.ForegroundColor = ConsoleColor.Green; //Console.WriteLine("Done!"); Console.ResetColor(); } Console.ReadKey(); }
private static void ImportData(SpDataContext spContext, bool clear) { if (clear) { //delete all items. while (spContext.List <Department>().Take(100).DeleteAll()) { spContext.SaveChanges(); } while (spContext.List <Employee>().Take(100).DeleteAll()) { spContext.SaveChanges(); } } spContext.List <Department>().AddOrUpdate(new Department() { Title = "Warner Brothers" }, 1); spContext.List <Employee>().AddOrUpdate(new Employee() { FirstName = "Emma", LastName = "Stone", Phone = "11-1111-111", Email = "*****@*****.**", Position = EmployeePosition.Manager }, 1); var specialist = new Employee() { FirstName = "Will", LastName = "Smith", Phone = "11-1143-222", Email = "*****@*****.**", Position = EmployeePosition.Specialist, DepartmentId = 1 }; specialist.Manager.EntityId = 1; //specialist.Department.EntityId = 1; spContext.List <Employee>().AddOrUpdate(specialist, 2); spContext.SaveChanges(); }
static void Main(string[] args) { string siteUrl = ConfigurationManager.AppSettings["siteUrl"]; while (string.IsNullOrWhiteSpace(siteUrl)) { Console.WriteLine("Enter Site Url: "); siteUrl = Console.ReadLine(); } string userPassword = ConfigurationManager.AppSettings["userPassword"]; Department[] departments; Employee[] employees; //using (var context = new MyContext()) //{ // departments = context.Departments/*.AsNoTracking()*/.ToArray(); // employees = context.Employees/*.AsNoTracking()*/.ToArray(); //} using (var clientContext = new ClientContext(siteUrl)) { string userLogin = ConfigurationManager.AppSettings["userLogin"]; while (string.IsNullOrWhiteSpace(userLogin)) { Console.WriteLine("Enter User Login: "******"Done!"); Console.ResetColor(); Console.ReadKey(); }