I'm new to asp .net core i have a issue related to `
Object reference not set to an instance of an object
.I created class names are destination , siteDestination ,site
destintination table has
destination_id ,name fields
Site table has siteId, sitecode fields
siteDestination table has composite key destination_id and siteId are integer
siteDestination and destintination have many-many relationship
I need to update destination table siteDestinationField so i get input as "siteDestinations":[1,2] in postman
i created dto object that has name, public List<int> SiteDestinations{ get; set; } property
i set mapper to dto class and destination class and ignore SiteDestinations property
when request made "siteDestinations":[1,2] it come to dto object .using mapping i translate into destination object except SiteDestinations
i check particular id using get method
then
destination.SiteDestinations.Add(new SiteDestination()); (debug untill then exception occur
then i call
var length=destinationDTO.SiteDestinations.Count;
for(var i=0;i<length;i++){
destination.SiteDestinations[i].DestinationId=destination.Id;
destination.SiteDestinations[i].SiteCodeId=destinationDTO.SiteDestinations[i];
}
when debug AND SEND REQUEST FROM POSTMAN it ignore the loop when debug finished it indicate
Object reference not set to an instance of an object. AS ERROR