0

Entity Framework の代わりに Dapper を使用しています。ネストされたオブジェクトをクエリ パラメータとして使用しようとすると、エラーが発生しました。

エラーは次のようになります。

Type App.Model.Device の Device のメンバーは、パラメーター値として使用できません。

質問構造を改善できるものがあれば、コメントしてください。バッシュしないでください。ありがとう

次のようなクラスがあります。

public class RootObject
{
    public List<Datum> data { get; set; }
}

public class Datum
{
    public Device device { get; set; }
    public long time { get; set; }
    public string data { get; set; }
}
public class Device
{
    public string id { get; set; }
}

そして、次のような SQL 挿入クエリ:

private const string InsertQuery = @"Insert into iot.[Table] (DeviceID,DeviceData,UnixTime) values(@device.id,@data,@time)";

ダッパー挿入機能:

  public CreateCommand(List<Datum> Datums)
        {
            _Datums = Datums;
        }
        public void Execute()
        {
            Insert();
        }
        private void Insert()
        {
            using (var connection = DatabaseConfiguration.SqlServer())
            {
                using (var transaction = connection.BeginTransaction())
                {
                    try
                    {
                        connection.Execute(InsertQuery, _Datums, transaction);
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
4

1 に答える 1