0

I'm getting an error:

SystemArguementNullException: 'Value cannot be null. Parameter name: entity'

When I leave off the AR_Reliability section the main other data columns are inserted without error.

public bool AddReport(Forms_Reports report)
{
    ctx.Forms_Reports.Add(report);
    ctx.SaveChanges();

    return true;
}

My JSON body looks like this:

[ 
   { 
      "AR_Reliability":[ 
         { 
            "Process_Consequence_Analysis":"Test_Pc HSS",
            "Reliability_Parameter_Deviations":"Test_Rp",
            "Equipment_Out_Of_Service":"Test_Eos",
            "Equipment_Returned_to_Service":"Test_Er",
            "Critical_Instrumentation_Failure":"Test_Ci",
            "Total_Equipment_Failure":"Test_Te",
            "Total_Single_Point_of_Failure":"Test_Spf",
            "Maintainence_Scheduled_or_InProgress":"Test_Mc",
            "Active_Permits":"Test_Ap",
            "Issues":"Test_I",
            "Inventory_Tank_Levels":"Test_It",
            "Stream_ID":null,
            "SPF_ID":null,
            "Ins_ID":null,
            "Eqp_ID":null,
            "DE_ID":1
         }
      ],
      "RoadClosures":"Test_Rc",
      "FirstMaintainStart":"Test_Fms",
      "PSR_AbnormalOperations":"Test_Ao",
      "FeedstockChanges":"Test_Fsc",
      "LineupChanges":"Test_Lc",
      "SafetyMeetings":"Test_Sm   ",
      "CR_AbnormalOperations":"Test_Ao",
      "HighPriorityAlarms":"Test_Hpa",
      "Impairment_to_fire_protection_systems":"Test_Ifp",
      "AlarmsInhibited":"Test_Ai",
      "FR_AbnormalOperations":"Test_Ao",
      "Maintenance":"Test_Mt   ",
      "CreatedDate":"2019-01-08T00:00:00",
      "UpdatedDate":"2019-01-08T00:00:00",
      "CreatedBy":"Dev HSS                                               ",
      "UpdatedBy":"Dev HSS                                               ",
      "Shift":"1    ",
      "Area_ID":1,
      "User_ID":1
   }
]

AR_Reliability is a related table in the database - There are other related tables too but just trying to add data for this one table to my Entity.

Selim Yildiz
  • 5,254
  • 6
  • 18
  • 28
LightStamp
  • 39
  • 7
  • Does this answer your question? [avoiding null reference exceptions](https://stackoverflow.com/questions/1943465/avoiding-null-reference-exceptions) – Jawad Jan 23 '20 at 21:10

2 Answers2

0

Isn't your JSON is List of object types and how you able to get data in an object?

public bool AddReport(List<Forms_Reports> report)
{
    
}
0

Your json looks like collection of one element. Try this:

public bool AddReport(IEnumerable<Forms_Reports> reports)
{
   ctx.Forms_Reports.AddRange(reports);
   ctx.SaveChanges();

   return true;
}

also it would be better to rename method in this case to AddReports

Maks Shapovalov
  • 154
  • 1
  • 6
  • It is always one report added. It's just that a report contains associated data to be also placed into another table. Does that help clarify? – LightStamp Jan 24 '20 at 16:49