Getting full entity on Swagger's POST, but I'm only looking for an Id Insert

Viewed 18

I'm facing a basic problem in my learning path trough API develompent with C#. I have all my entities setted by codefirst approach. Here's one of them.

Frameworks:

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
 public int Id { get; set; }

        [Required]
        public string rowId { get; set; }

        public string Name { get; set; }
        public string Description { get; set; }
        [Required]
        [ForeignKey("FrameworkCategoryId")]
        public FrameworkCategory FrameworkCategory { get; set; }
        public bool Deleted { get; set; }
        public DateTime InsertDateTime { get; set; }
        public float TimeStamp { get; set; }

This Frameworks entity has a foreign key referencing FrameworkCategory, and for migration purposes, I have one FrameworkCategory with the entity's type.This creates the column FrameworkCategoryId in my DB. but when I come to POST on swaggerUI I have this Json for inserting.

{
  "id": 0,
  "rowId": "string",
  "name": "string",
  "description": "string",
  "frameworkCategory": {
    "id": 0,
    "rowId": "string",
    "name": "string",
    "description": "string",
    "isMasterRoot": true,
    "hashKey": "string",
    "frameworkCategoryId": 0,
    "isRoot": true,
    "depthLevel": 0,
    "deleted": true,
    "insertDateTime": "2022-09-22T15:25:49.933Z",
    "timeStamp": 0
  },
  "deleted": true,
  "insertDateTime": "2022-09-22T15:25:49.933Z",
  "timeStamp": 0
}  

As you can see, it brings all the entity FrameworkCategory instead to just the CategoryId to insert into foreignkey.

0 Answers
Related