public static void Main(string[] args) { //CreateHostBuilder(args).Build().Run(); var options = new Microsoft.EntityFrameworkCore.DbContextOptions <DemoContext>(); DemoContext context = new DemoContext(options); var customer = context.Customers.Where(c => c.Name == "Emmanuel Toledo").FirstOrDefault(); System.Console.ForegroundColor = System.ConsoleColor.Cyan; System.Console.WriteLine($"Found customer {customer.Name}"); //Lazy Loading... System.Console.WriteLine("with the following orders:"); foreach (var order in customer.Orders) { System.Console.WriteLine($"Order {order.Number} with a total charge amount ${order.ChargeAmount}"); System.Console.WriteLine("-- Products bought --"); int count = 0; foreach (var orderProduct in order.OrderProducts) { count++; System.Console.WriteLine($"{count}. {orderProduct.Product.Name} costing ${orderProduct.Product.Cost}"); } } System.Console.ReadLine(); }
public RazorRenderer(string rootPath) { this.rootPath = rootPath; services = new ServiceCollection(); ConfigureDefaultServices(services); Microsoft.EntityFrameworkCore.DbContextOptions <MailDemonDatabase> dbOptions = MailDemonDatabaseSetup.ConfigureDB(null); services.AddTransient <MailDemonDatabase>((provider) => new MailDemonDatabase(dbOptions)); serviceProvider = services.BuildServiceProvider(); viewRenderer = new ViewRenderService(rootPath, serviceProvider.GetRequiredService <IRazorViewEngine>(), null, null, serviceProvider); }
private static IEnumerable <EventViewModel> GetEvents(string userName) { UserData userData = new UserData(); var options = new Microsoft.EntityFrameworkCore.DbContextOptions <ApplicationDbContext>(); using (var db = new ApplicationDbContext(options)) { userData = db.UserData.FirstOrDefault(u => u.UserName == userName); } return(userData.Events); }
public static void AddAttendee(AttendeeViewModel collection, string userName) { // Get an instance of the DB var options = new Microsoft.EntityFrameworkCore.DbContextOptions <ApplicationDbContext>(); using (var db = new ApplicationDbContext(options)) { var userData = db.UserData.FirstOrDefault(u => u.UserName == userName); var eventViewModel = userData.Events.FirstOrDefault(e => e.Name == collection.EventName); eventViewModel.Attendees.Add(collection); db.SaveChanges(); } }
static async Task Main(string[] args) { var options = new Microsoft.EntityFrameworkCore.DbContextOptions <SalesOrderContext>(); var salesOrderContext = new SalesOrderContext(options); var serviceBusHelper = new StorageQueueHelper(); var testFileHelper = new TextFileHelper(); var productRepository = new ProductRepository(testFileHelper); var productService = new ProductService(productRepository); var salesOrderRepository = new SalesOrderRepository(salesOrderContext); var salesOrderService = new SalesOrderService(salesOrderRepository); var salesOrderProcessor = new SalesOrderProcessor( serviceBusHelper, productService, salesOrderService); await salesOrderProcessor.Run(); }
public void SaveToDb(List <Station> stations = null) { List <Station> datas = stations; var option = new Microsoft.EntityFrameworkCore.DbContextOptions <ApplicationDbContext>(); ApplicationDbContext db = new ApplicationDbContext(option); if (stations == null || stations.Count == 0) { datas = this.FindStations(); } datas.ForEach(item => { db.Stations.Add(item); }); db.SaveChanges(); }
static async Task Main(string[] args) { // How manu to create? int salesOrderCount = int.Parse(args[0]); // Set-up Helpers and Dependencies var serviceBusHelper = new StorageQueueHelper(); var textFileHelper = new TextFileHelper(); // Set-up data access var options = new Microsoft.EntityFrameworkCore.DbContextOptions <SalesOrderContext>(); var salesOrderContext = new SalesOrderContext(options); var productRepository = new ProductRepository(textFileHelper); var productService = new ProductService(productRepository); var salesOrderRepository = new SalesOrderRepository(salesOrderContext); var consoleLogger = new ConsoleLogger(); // Process sales orders - will run forever var generateSalesOrders = new GenerateSalesOrders( serviceBusHelper, productService, consoleLogger); await generateSalesOrders.Run(salesOrderCount); }
// here is the constructor. It takes a parameter of 'options'. 'options' is of type Microsoft.EntityFrameworkCore.DbContextOptions // it calls the constructor for the Microsoft.EntityFrameworkCore.DbContextOptions parent class public ApplicationDbContext(Microsoft.EntityFrameworkCore.DbContextOptions <ApplicationDbContext> options) : base(options) { }
public IdentityContext(Microsoft.EntityFrameworkCore.DbContextOptions <IdentityContext> ops) : base(ops) { }
public DatabaseContext(Microsoft.EntityFrameworkCore.DbContextOptions <DatabaseContext> options) : base(options) { }
public NegocioContext(Microsoft.EntityFrameworkCore.DbContextOptions <NegocioContext> options) : base(options) { }
public ApiAuthorizationDbContext(Microsoft.EntityFrameworkCore.DbContextOptions options, Microsoft.Extensions.Options.IOptions <IdentityServer4.EntityFramework.Options.OperationalStoreOptions> operationalStoreOptions) { }
public MaisCadastrosContext(Microsoft.EntityFrameworkCore.DbContextOptions options) : base(options) { }
public UserDbContext(Microsoft.EntityFrameworkCore.DbContextOptions <UserDbContext> options) : base(options) { }
IServiceProvider IStartup.ConfigureServices(IServiceCollection services) { services.AddMemoryCache((o) => { o.CompactionPercentage = 0.9; o.ExpirationScanFrequency = TimeSpan.FromMinutes(1.0); o.SizeLimit = 1024 * 1024 * 32; // 32 mb }); bool enableWeb = bool.Parse(Configuration.GetSection("mailDemonWeb")["enable"]); if (enableWeb) { services.Configure <CookiePolicyOptions>(options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.Configure <CookieTempDataProviderOptions>(options => { options.Cookie.IsEssential = true; }); services.Configure <GzipCompressionProviderOptions>(options => options.Level = System.IO.Compression.CompressionLevel.Optimal); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(o => { o.AccessDeniedPath = "/MailDemonLogin"; o.LoginPath = "/MailDemonLogin"; o.LogoutPath = "/MailDemonLogin"; o.Cookie.HttpOnly = true; }); services.AddResponseCompression(options => { options.EnableForHttps = true; }); services.AddResponseCaching(); services.AddHttpContextAccessor(); services.AddSingleton <IMailSender>((provider) => mailService); services.AddSingleton <IBulkMailSender>((provider) => new BulkMailSender(provider)); services.AddSingleton <IViewRenderService, ViewRenderService>(); services.AddSingleton <IAuthority>(this); services.AddSingleton <IMailDemonDatabaseProvider>(this); services.AddTransient <IMailCreator, MailCreator>(); Microsoft.EntityFrameworkCore.DbContextOptions <MailDemonDatabase> dbOptions = MailDemonDatabaseSetup.ConfigureDB(Configuration); services.AddTransient <MailDemonDatabase>((provider) => new MailDemonDatabase(dbOptions)); services.AddHostedService <SubscriptionCleanup>(); services.AddDataProtection().SetApplicationName(GetType().Name).PersistKeysToFileSystem(new System.IO.DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory)); services.AddMvc((options) => { }).SetCompatibilityVersion(CompatibilityVersion.Latest).AddJsonOptions(options => { options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; }); services.Configure <RazorViewEngineOptions>(opts => { opts.AllowRecompilingViewsOnFileChange = true; opts.FileProviders.Add(new MailDemonDatabaseFileProvider(this, RootDirectory)); }); services.AddAntiforgery(options => { options.Cookie.Name = "ANTI_FORGERY_C"; options.FormFieldName = "ANTI_FORGERY_F"; options.HeaderName = "ANTI_FORGERY_H"; options.SuppressXFrameOptionsHeader = false; }); } return(serviceProvider = services.BuildServiceProvider()); }
public SqlServerDbContextFactory(Microsoft.EntityFrameworkCore.DbContextOptions dbContextOptions) { _dbContextOptions = dbContextOptions; }
public IdentityUserContext(Microsoft.EntityFrameworkCore.DbContextOptions options) { }
public UsersContext(Microsoft.EntityFrameworkCore.DbContextOptions <UsersContext> options) : base(options) { Database.EnsureCreated(); }
public DatabaseContext (Microsoft.EntityFrameworkCore.DbContextOptions <DatabaseContext> options) : base(options: options) { // TODO Database.EnsureCreated(); }
/// <summary> /// Initializes a new instance of the <see cref="CustomerStore"/> class. /// </summary> /// <param name="users">The users.</param> public CustomerStore(Microsoft.EntityFrameworkCore.DbContextOptions <LoyaltyContext> options) { _context = new LoyaltyContext(options); }
public LoginContext(Microsoft.EntityFrameworkCore.DbContextOptions <LoginContext> options) : base(options) { }
public BFIdentityContext(Microsoft.EntityFrameworkCore.DbContextOptions options) : base(options) { }
public async Task <HashesInfo> CalculateHashesInfo(ILogger logger, Microsoft.EntityFrameworkCore.DbContextOptions <BloggingContext> dbContextOptions, CancellationToken token = default) { using (var client = new DocumentClient(new Uri(_endpoint), _key)) { HashesInfo hi = null; try { if (GetHashesInfoFromDB().Result != null) { if (logger != null) { logger.LogInformation(0, $"###Leaving calculation of initial Hash parameters; already present"); } return(GetHashesInfoFromDB().Result); } if (logger != null) { logger.LogInformation(0, $"###Starting calculation of initial Hash parameters"); } hi = new HashesInfo { ID = 0, IsCalculating = true }; _hashesInfoStatic = hi; //temporary save to static to indicate calculation and block new calcultion threads var collection_link = UriFactory.CreateDocumentCollectionUri(_databaseId, _collectionId); //var alphabet = client.CreateDocumentQuery<DocumentDBHash>(collection_link) // .Select(f => f.Key.First()) // .Distinct() // .OrderBy(o => o); int.TryParse(client.CreateDocumentQuery <DocumentDBHash>(collection_link) .OrderByDescending(x => x.Key).Take(1).ToArray().FirstOrDefault().Id, out int count); var key_length = client.CreateDocumentQuery <int>(collection_link, "SELECT TOP 1 VALUE LENGTH(c.Key) FROM c").ToAsyncEnumerable().First(); hi.Count = count; hi.KeyLength = await key_length; hi.Alphabet = "fakefakefake"; //string.Concat(alphabet); hi.IsCalculating = false; if (logger != null) { logger.LogInformation(0, $"###Calculation of initial Hash parameters ended"); } } catch (Exception ex) { if (logger != null) { logger.LogError(ex, nameof(CalculateHashesInfo)); } hi = null; } finally { _hashesInfoStatic = hi; } return(hi); } }