I'm trying to iterate in each row from a list, if the current row from the list has no record yet in the database hence add the current row, otherwise continue to next iteration. how can i add the current row in the list to my DbSet.
list.ForEach(x =>
{
objInsuredList = (from obj in _db.dbLifeData
where (obj.identifier == x.identifier) && (obj.plan == x.plan) && (obj.policyno == x.policyno)
select obj).ToList(); //get all existing record
var query = _db.dbLifeData.FirstOrDefault(y => y.identifier == x.identifier
&& y.policyno == x.policyno && y.plan == x.plan); //check current in list if it exists
if(query != null)
{
query.status = x.status;
_db.Entry(query).State = EntityState.Modified;
_db.SaveChanges();
}
else //current row has no record yet in the dbLifeData database
{
}
});