I have a challenge that I have searched online couldn't find an answer for it. I have a class which I create a list from:
public class PairingList
{
public int PlayerId { get; set; }
public int OpponentId { get; set; }
}
var getAll = await _db.TblResult.ToListAsync();
foreach (var row in pairingList)
{
getAll.FirstOrDefault(a =>a.Id==row.PlayerId).Round1_Opp
= row.OpponentId;
getAll.FirstOrDefault(a
=>a.Id==row.OpponentId).Round1_Opp = row.PlayerId;
}
_db.Update(getAll);
_db.SaveChangesAsync();
I get all of the results from db and would like to update based on pairingList and save into the db.
After the compiling code I get following error:
NullReferenceException: Object reference not set to an instance of an object.