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.
Connected.Framework.Service.../Connected.ServiceModel.Clie.../TableDataConnection.cs

63 lines
1.5 KiB

using System.Data;
using Connected.Annotations;
2 years ago
using Connected.Data.Storage;
using Connected.ServiceModel.Client.Data.Remote;
2 years ago
using Microsoft.Data.SqlClient;
namespace Connected.ServiceModel.Client.Data;
[ServiceRegistration(ServiceRegistrationMode.Auto, ServiceRegistrationScope.Transient)]
internal sealed class TableDataConnection : DatabaseConnection
{
public TableDataConnection(RemoteTableService tables, ICancellationContext context) : base(context)
2 years ago
{
Tables = tables;
2 years ago
}
private RemoteTableService Tables { get; }
2 years ago
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 TableConnection(Tables, ConnectionString);
2 years ago
}
}