.net core 如何在.net核心api中将多个实体或json作为参数传递

.net core 如何在.net核心api中将多个实体或json作为参数传递,.net-core,odata,.net Core,Odata,我是编程新手。我读了一篇关于.NETCoreAPI的教程,但我注意到每一篇教程都只展示了如何将实体类作为参数传递。若我想传递如下实体类的组合,这是否意味着我需要向服务器提交多个post请求 JSON: C: 您需要像上面那样更改对象 然后,您需要返回type List您可以创建一个viewModel来将json解析为一个对象。像这样 public class Post { [Key] public string postId { get; set; } publ

我是编程新手。我读了一篇关于.NETCoreAPI的教程,但我注意到每一篇教程都只展示了如何将实体类作为参数传递。若我想传递如下实体类的组合,这是否意味着我需要向服务器提交多个post请求

JSON:

C:

您需要像上面那样更改对象
然后,您需要返回type List

您可以创建一个viewModel来将json解析为一个对象。像这样

   public class Post
{
    [Key]
    public string postId { get; set; }
    public string postText { get; set; }
    public IEnumerable<Item> items {get; set;}

}

public class Item
{
    [Key]
    public string itemid{ get; set; }
    public string postId { get; set; } 
 }

public IActionResult Post([FromBody] Post post)
    {
        var entity = JsonConvert.DeserializeObject<PostViewModel>(post.ToString())
        return Ok(data);
    }
public class Post
{
    [Key]
    public string postId { get; set; }
    public string postText { get; set; }
}

public class Item
{
    [Key]
    public string itemid{ get; set; }
    public string postId { get; set; } 
 }

public IActionResult Post([FromBody] Post post)
{
    return Ok(data);
}
public class Post
{
    [Key]
    public string postId { get; set; }
    public string postText { get; set; }
    public List<Item> items {get; set;}

}

public class Item
{
    [Key]
    public string itemid{ get; set; }
    public string postId { get; set; } 
 }
   public class Post
{
    [Key]
    public string postId { get; set; }
    public string postText { get; set; }
    public IEnumerable<Item> items {get; set;}

}

public class Item
{
    [Key]
    public string itemid{ get; set; }
    public string postId { get; set; } 
 }

public IActionResult Post([FromBody] Post post)
    {
        var entity = JsonConvert.DeserializeObject<PostViewModel>(post.ToString())
        return Ok(data);
    }