You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.3 KiB
60 lines
1.3 KiB
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<IDbConnection> OnCreateConnection()
|
|
{
|
|
await Task.CompletedTask;
|
|
|
|
return new SqlConnection(ConnectionString);
|
|
}
|
|
}
|