public async Task CreatePerson() { while (true) { var flag = true; using (var context = new SomeContext()) { Console.WriteLine("Do you want to add a person in table?(type \"y\" ifyes, \"other key\" if not)"); string answer = Console.ReadLine(); if (answer != "y") { break; } while (flag) { var person = new Person(); Console.WriteLine("\nEnter name:"); person.Name = Console.ReadLine(); if (context.Persons.All(x => x.Name != person.Name)) { flag = false; context.Add(person); context.SaveChanges(); } else { Console.WriteLine($"This person is already in table, choose another name!"); } } } } }
[Fact] // CodePlex 2029 public void InitializeDatabase_does_not_create_new_connections() { using (var context = new SomeContext()) { context.Database.Initialize(force: false); using (var transactionContext = new SomeTransactionContext(context.Database.Connection)) { var initializer = new TransactionContextInitializer <TransactionContext>(); var recorder = new ConnectionRecorder(); DbInterception.Add(recorder); try { using (transactionContext.Database.BeginTransaction()) { initializer.InitializeDatabase(transactionContext); } Assert.Equal(1, recorder.Connections.Count); } finally { DbInterception.Remove(recorder); } } } }
[Fact] // CodePlex 2029 public void InitializeDatabase_does_not_create_new_connections() { using (var context = new SomeContext()) { context.Database.Initialize(force: false); using (var transactionContext = new SomeTransactionContext(context.Database.Connection)) { var initializer = new TransactionContextInitializer<TransactionContext>(); var recorder = new ConnectionRecorder(); DbInterception.Add(recorder); try { using (transactionContext.Database.BeginTransaction()) { initializer.InitializeDatabase(transactionContext); } Assert.Equal(1, recorder.Connections.Count); } finally { DbInterception.Remove(recorder); } } } }
public async Task Choose() { using (var context = new SomeContext()) { var row = context.Persons.OrderBy(x => Guid.NewGuid()).ToList(); Mixed mix = new Mixed(); mix.Mixing(); Person temp = null; foreach (var person in row) { if (temp != null) { temp.GiftedFriend = person.Name; } else { row.Last().GiftedFriend = person.Name; } temp = person; } Console.WriteLine($"\nThe list of people who gives gifts to whom (to check that no one is offended):\n"); foreach (var item in context.Persons) { Console.WriteLine($"{item.Name} gifts to {item.GiftedFriend}"); } context.SaveChanges(); } }
public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node) { // just sample check if (node.Url.StartsWith("/Administration/")) { return(context.User.Identity.Name == "admin"); } // or you can query your db using (var dbContext = new SomeContext()) { var userName = context.User.Identity.Name; var currentUser = dbContext.Users.First(u => u.AccountName == userName); if (node.Url.StartsWith("/Administration/") && currentUser.Permission.IsAllowdAdminsPage) { return(true); } // others checks } // or you can access your current page and get data from it var currentPage = context.Handler as Page; if (currentPage != null) { var someControl = currentPage.FindControl("someControl"); // some custom checks } return(base.IsAccessibleToUser(context, node)); }
public MainWindow() { InitializeComponent(); var context = new SomeContext(); DataContext = context; context.AddPerson(); }
//[Test, TestCaseSource(typeof(MyFactoryClass), "TestCases")] public override int[] ExecuteParams(DataTablesParam dataTablesParam) { DataContext.Dispose(); //reset datacontext in order to clear local DataContext = new SomeContext(); int[] returnVar = base.ExecuteParams(dataTablesParam); Assert.AreEqual(returnVar.Length, DataContext.Models.Local.Count, "records loaded in memory"); return(returnVar); }
public override int[] ExecuteParams(DataTablesParam dataTablesParam) { DataContext.Dispose(); //reset datacontext in order to clear local DataContext = new SomeContext(); int[] returnVar = base.ExecuteParams(dataTablesParam); Assert.AreEqual(returnVar.Length, DataContext.Models.Local.Count, "records loaded in memory"); return returnVar; }
public void Execute(SomeContext context) { var data = context.GetStorage <TType>().Cast <IEntityWithSomeFunction>(); foreach (var item in data) { item.SomeFunction(); } }
private static SomeContext CreateDb() { var context = new SomeContext(); Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "", string.Format("Data Source=\"{0}\";Password={1}", DbFile, Password)); context.Database.Initialize(true); return context; }
public void store_and_retrieve() { var context = new TestContext(); var data = new SomeContext(); context.Store(data); context.Retrieve <SomeContext>().ShouldBeTheSameAs(data); }
public SomeContextScope(object stateData1, object stateData2) { if (SomeContext.Current == null) { SomeContext context = new SomeContext(stateData1, stateData2); SomeContext.Current = context; m_contextCreated = true; } }
public T DoIt(SomeContext someContext, string name) { string contextVal = someContext.GetValue(name); var thing = new T { MyProperty = contextVal }; return(thing); }
public void ShowMan() { using (var context = new SomeContext()) { Console.WriteLine($"Enter your name to find out who you are buying the gift for:\n"); var yourName = Console.ReadLine(); var recipient = context.Persons.Single(x => x.Name == yourName).GiftedFriend; Console.WriteLine($"{yourName} you're {recipient}'s SS agent, congratulations!!!\n"); } }
public void SimpleInterfaceRoutingWithContextShouldWork() { var processor = Substitute.For <IMessageHandler <SomeContext, SomeDto> >(); var router = RoutingTestEnvironment.GetInterfaceBasedRoutingProvider(processor); var routedObject = RoutingTestEnvironment.GetTestDtoData(); var context = new SomeContext(); router.RouteObject(context, routedObject); processor.Received().HandleMessage(context, routedObject); }
public void ShowFallPass() { int count = 0; while (count <= Password.Length) { Console.Write(SomeContext.HidePass(Password.Length)); count++; } }
internal string GetDogName(SomeContext <ComplexData> context) { var name = _dog.Name; context.Collection.Add(new ComplexData() { Name = name }); return(name); }
public void Dto_with_no_properties_causes_null_exception() { using (var context = new SomeContext(InMemoryOptions.Create <SomeContext>())) { //ATTEMPT var ex = Assert.Throws <InvalidOperationException>(() => context.SetupSingleDtoAndEntities <ImutableDto>()); //VERIFY ex.Message.ShouldEqual("The ImutableDto class inherits ILinkToEntity<T> but has no properties in it!"); } }
public void ShowTableOfPersons() { using (var context = new SomeContext()) { Console.WriteLine($"This is table of persons:"); foreach (var personInTable in context.Persons) { Console.WriteLine($"{personInTable.Id} --- {personInTable.Name}"); } } }
public void Dto_with_no_properties_causes_null_exception() { using (var context = new SomeContext(InMemoryOptions.Create <SomeContext>())) { //ATTEMPT var ex = Assert.Throws <InvalidOperationException>(() => context.SetupSingleDtoAndEntities <ImutableDto>()); //VERIFY ex.Message.ShouldEqual("A DTO using the ILinkToEntity<T> must contain at least one Property!"); } }
public EntityFramework() { var oldQueryable = SomeModelQueryable; DataContext = new SomeContext(); DataContext.Database.Initialize(true); foreach (var sm in oldQueryable) { DataContext.Models.Add(sm); } DataContext.SaveChanges(); }
static async Task Main(string[] args) { using (var context = new SomeContext()) { await context .Customers .Where(c => c.Email.Contains("42")) .CustomUpdateAsync((c) => new Customer() { Email = "4242" }); } }
public EntityFramework(IDbConnectionFactory connectionFactory) { _defaultConnectionFactory = Database.DefaultConnectionFactory; Database.DefaultConnectionFactory = connectionFactory; var oldQueryable = SomeModelQueryable; DataContext = new SomeContext(); DataContext.Database.Initialize(true); foreach (var sm in oldQueryable) { DataContext.Models.Add(sm); } DataContext.SaveChanges(); }
public void InitTest() { DataContext = new SomeContext(); Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "", string.Format("Data Source=\"{0}\";Password={1}", DbFile, Password)); DataContext.Database.Initialize(true); for (var i = 0; i < 100; i++) { DataContext.Models.Add(new SomeModel() {DisplayName = "Name " + i}); } DataContext.SaveChanges(); }
public void DeleteAll() { using (var context = new SomeContext()) { Console.WriteLine($"Do you wanna delete whole table? (type \"y\" if yes, \"other key\" if not)"); var answer = Console.ReadLine(); if (answer == "y") { var table = context.Persons.Where(x => x.Name != null); context.Persons.RemoveRange(table); context.SaveChanges(); } } }
public EntityFramework(IDbConnectionFactory connectionFactory) { _defaultConnectionFactory = Database.DefaultConnectionFactory; Database.DefaultConnectionFactory = connectionFactory; var oldQueryable = SomeModelQueryable; DataContext = new SomeContext(); DataContext.Database.Initialize(true); foreach (var sm in oldQueryable) { DataContext.Models.Add(sm); } DataContext.SaveChanges(); }
public EntityFramework(SomeContext dataContext) { DataContext = dataContext; if (DataContext.Models.Any()) { DataContext.Database.ExecuteSqlCommand("DELETE FROM SomeModels"); } foreach (var sm in SomeModelQueryable) { DataContext.Models.Add(sm); } DataContext.SaveChanges(); SomeModelQueryable = DataContext.Models; }
static void Main(string[] args) { _connection = $"Host={args[0]};Port={args[1]};Username={args[2]};Password={args[3]};Database=some_context;"; using (var ctx = new SomeContext()) { ctx.Database.EnsureCreated(); var _ = ctx.SomeDateTimes .Where(s => s.Updated > DateTime.Now.AddDays(-1)) .ToArray(); ctx.Database.EnsureDeleted(); } Console.WriteLine("Finished!"); }
public void DeletePerson() { using (var context = new SomeContext()) { Console.WriteLine($"Do you wanna delete someone from table? (type \"y\" ifyes, \"other key\" if not)"); var answer = Console.ReadLine(); if (answer == "y") { ShowTable showTable = new ShowTable(); showTable.ShowTableOfPersons(); Console.WriteLine($"Choose who will be deleted from table. (choose number)"); var id = int.Parse(Console.ReadLine()); var person = new Person { Id = id }; context.Persons.Remove(person); context.SaveChanges(); } } }
// If you have already instantiated a context to use, then you can pass it in here public RoleManager <IdentityRole> Create(SomeContext context) { return(new RoleManager <IdentityRole>(new RoleStore <IdentityRole, string>(context))); }
public HomeController(SomeContext context) { _context = context; }
private void RetHifhtPas(string Password) { Pass = SomeContext.HidePass(Password.Length); }
public void store_and_retrieve() { var context = new TestContext(); var data = new SomeContext(); context.Store(data); context.Retrieve<SomeContext>().ShouldBeTheSameAs(data); }
public static string ReturnBadTime() { return(SomeContext.GetDate(saveDayBad, saveHourBad, saveMinutesBad, saveSecBad)); }
public SomeRescueContextImpl(SomeContext context, Exception exception) : base(context) { Exception = exception; }
public static string ReturnGoodTime() { return(SomeContext.GetDate(saveDayGood, saveHourGood, saveMinutesGood, saveSecGood)); }
public DashboardController(SomeContext context) { _context = context; }