public async Task <IEnumerable <dynamic> > ConvertAsync(MsSqlDbAttribute input, CancellationToken cancellationToken) { var context = _msSqlDbExtensionConfigProvider.CreateContext(input); var sqlSpec = new MsSqlSpec() { Parameters = input.SqlQueryParameters, Query = input.SqlQuery }; var list = new List <object>(); #if NETCOREAPP3_1 var objects = context.MsSqlDbService.GetAsync(sqlSpec, cancellationToken); await foreach (var o in objects.WithCancellation(cancellationToken)) { list.Add(o); } #else var objects = await context.MsSqlDbService.GetAsync(sqlSpec, cancellationToken); list.AddRange(objects); #endif return(list.AsEnumerable()); }
public MsSqlDbContext CreateContext(MsSqlDbAttribute input) { var resolvedConnectionString = ResolveConnectionString(input.ConnectionStringSetting); var service = GetService(resolvedConnectionString); return(new MsSqlDbContext() { Attribute = input, MsSqlDbService = service }); }
public Task <T> ConvertAsync(MsSqlDbAttribute input, CancellationToken cancellationToken) { var context = _msSqlDbExtensionConfigProvider.CreateContext(input); var sqlSpec = new MsSqlSpec() { Parameters = input.SqlQueryParameters, Query = input.SqlQuery }; return(context.MsSqlDbService.GetOne <T>(sqlSpec, cancellationToken)); }
private void ValidateConnection(MsSqlDbAttribute attribute, Type paramType) { if (string.IsNullOrEmpty(_options.ConnectionString) && string.IsNullOrEmpty(attribute.ConnectionStringSetting) && string.IsNullOrWhiteSpace(_defaultConnectionString)) { var attributeProperty = $"{nameof(MsSqlDbAttribute)}.{nameof(MsSqlDbAttribute.ConnectionStringSetting)}"; var optionsProperty = $"{nameof(MsSqlDbOptions)}.{nameof(MsSqlDbOptions.ConnectionString)}"; throw new InvalidOperationException( $"The CosmosDB connection string must be set either via the '{Constants.DefaultConnectionStringName}' IConfiguration connection string, via the {attributeProperty} property or via {optionsProperty}."); } }