public Repository(Webstore.WebModel dbctx) { #pragma warning disable IDE0021 // Use expression body for constructors EfDomain = dbctx; #pragma warning restore IDE0021 // Use expression body for constructors // var ObjCtx = (EfDomain as IObjectContextAdapter).ObjectContext; // ObjCtx.SavingChanges += OnSavingChanges; }
public BulkRepository(Webstore.WebModel dbctx, IAsyncPolicy retryPolicy) { Policy = retryPolicy; Debug.Assert(stagingNames.Length == (int)Staging_enum.NumberOfColumns && stagingTypes.Length == (int)Staging_enum.NumberOfColumns, "Staging_enum metadata is incorrect"); Debug.Assert(p_ActionWebPageParams.Length == (int)Action_enum.NumberOfColumns, "Action_enum metadata is incorrect"); //EF component (single context, but SaveChangesAsync after request[I] can overlap request[I+1] doing its Downloader work in parallel EfDomain = dbctx; // var ObjCtx = (EfDomain as IObjectContextAdapter).ObjectContext; // ObjCtx.SavingChanges += OnSavingChanges; // ADO component var csb = new SqlConnectionStringBuilder(EfDomain.Database.Connection.ConnectionString) { ApplicationName = "DICKBULKSPROC", // AsynchronousProcessing = false, ConnectRetryCount = 10, ConnectRetryInterval = 2, ConnectTimeout = 60, MultipleActiveResultSets = false, Pooling = false }; _conn = new SqlConnection(csb.ConnectionString); // independent SPID so EF & ADO can free-run truncateCmd = new SqlCommand("truncate table " + TGTTABLE, _conn); addLinksCmd = new SqlCommand("exec dbo.p_ActionWebPage @PageId,@Url", _conn); addLinksCmd.Parameters.AddRange(p_ActionWebPageParams); _bulk = new SqlBulkCopy(_conn) { DestinationTableName = TGTTABLE, BatchSize = 500, BulkCopyTimeout = 45 }; #if WIP LastAdoCmd = AdoWipEnum.Open; #endif AdoWip = (_conn.State != ConnectionState.Open) ? Policy.ExecuteAsync(() => _conn.OpenAsync()) // start the OPEN handshake async so we can do setup stuff in parallel : Task.FromResult <bool>(true); dataCaches[0] = MakeStagingTable(); // does not need _conn to be open yet run for (var i = 1; i < CACHELEN; i++) { dataCaches[i] = dataCaches[0].Clone(); // copy structure (but not data) } // wait for OPEN then create remote table on SQL asynchronously AdoWip = AdoWip.ContinueWith( t => Policy.ExecuteAsync(() => CreateStagingAsync()), TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); }