var application = DemoDBEntities.DefaultManager.Applications.FirstOrDefault();
//Comment out this code to make the role addition work.
// --------------------------------------------------
User user = DemoDBEntities.DefaultManager.CreateEntity<User>();
DemoDBEntities.DefaultManager.AddEntity(user);
user.UserID = Guid.NewGuid();
user.FirstName = "First Name";
user.Applications.Add(application);
DemoDBEntities.DefaultManager.RejectChanges();
DemoDBEntities.DefaultManager.SaveChanges(); //Save does not throw an excepton.
//--------------------------------------------------
var role = DemoDBEntities.DefaultManager.CreateEntity<Role>();
var systemFunction = DemoDBEntities.DefaultManager.SystemFunctions.FirstOrDefault();
role.SystemFunctions.Add(systemFunction);
role.Name = "Name";
role.Description = "Description";
role.RoleID = Guid.NewGuid();
role.Application = application;
DemoDBEntities.DefaultManager.SaveChanges();