using Connected.Annotations; using Connected.Data.Storage; using Microsoft.Data.SqlClient; using System.Data; namespace Connected.ServiceModel.Client.Data; [ServiceRegistration(ServiceRegistrationMode.Auto, ServiceRegistrationScope.Transient)] internal sealed class TableDataConnection : DatabaseConnection { public TableDataConnection(ICancellationContext context) : base(context) { } protected override void SetupParameters(IStorageCommand command, IDbCommand cmd) { if (cmd.Parameters.Count > 0) { foreach (SqlParameter i in cmd.Parameters) i.Value = DBNull.Value; return; } if (command.Operation.Parameters is null) return; foreach (var i in command.Operation.Parameters) { cmd.Parameters.Add(new SqlParameter { ParameterName = i.Name, DbType = i.Type, Direction = i.Direction }); } } protected override object GetParameterValue(IDbCommand command, string parameterName) { if (command is SqlCommand cmd) return cmd.Parameters[parameterName].Value; return null; } protected override void SetParameterValue(IDbCommand command, string parameterName, object value) { if (command is SqlCommand cmd) cmd.Parameters[parameterName].Value = value; } protected override async Task OnCreateConnection() { await Task.CompletedTask; return new SqlConnection(ConnectionString); } }