简单的OData客户端 - 在对象中发布集合/列表在OData API中作为空发送

时间:2018-06-14 16:03:36

标签: c# odata

var client = new ODataClient(new ODataClientSettings(host) { IgnoreResourceNotFoundException = true, OnTrace = (x, y) => Console.WriteLine(string.Format(x, y)) });
                List<Transaction> transactions = GetSampleTransactions();
                TransactionSet ts = await client.For<TransactionSet>().Set(new TransactionSet { TransactionSetId = 50, Transactions = transactions }).InsertEntryAsync(true).ConfigureAwait(false);

上面的代码,用于调用API并在&#34;事务集中发布事务列表&#34;:

[EnableQuery]
public class TransactionSet
{
    public int TransactionSetId { get; set; }

    [AutoExpand]        
    public List<Transaction> Transactions { get; set; }
}

以下代码包括API HttpPost:

[HttpPost]
public IActionResult Post([FromBody] TransactionSet transactions)
{
    var t = new TransactionSet();
    // TODO: Save transactions;
    return Created(transactions);
}

问题在于&#34;交易&#34;对象虽然包含TransactionSetId为50,但是Transactions属性为null。我知道我可以使用批处理代码并一次发送一条记录数据,这在我的情况下是低效的,所以我希望发布一个简单的列表。简单的Odata客户端不允许吗???为什么它将它作为null发送!?

0 个答案:

没有答案