DEV Community

Supraja Tangella
Supraja Tangella

Posted on

𝗧𝗼𝗱𝗮𝘆'𝘀 𝗖𝗼𝗱𝗶𝗻𝗴 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲𝘀 & 𝗙𝗶𝘅𝗲𝘀 𝗶𝗻 𝗠𝘆 𝗝𝗼𝗯 𝗔𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗧𝗿𝗮𝗰𝗸𝗲𝗿 𝗣𝗿𝗼𝗷𝗲𝗰𝘁 💻📬

🛠️ 𝗪𝗵𝗮𝘁 𝗜 𝗪𝗼𝗿𝗸𝗲𝗱 𝗢𝗻 𝗧𝗼𝗱𝗮𝘆:

✅ Checked if the email was 𝘀𝘂𝗰𝗰𝗲𝘀𝘀𝗳𝘂𝗹𝗹𝘆 𝘀𝗲𝗻𝘁 𝘁𝗼 𝘁𝗵𝗲 𝗰𝗼𝗺𝗽𝗮𝗻𝘆.

✅ If successful, set IsReminderSent = true.

✅ Used UpdateRange() to 𝗯𝘂𝗹𝗸 𝘂𝗽𝗱𝗮𝘁𝗲 𝗳𝗼𝗹𝗹𝗼𝘄-𝘂𝗽 𝗿𝗲𝗰𝗼𝗿𝗱𝘀 in the database.

❗ Faced an exception due to the User navigation property being tracked.

✅ 𝗙𝗶𝘅: Set followUp.User = null before updating to prevent tracking conflicts.

✅ Data updated successfully!

💡 𝗖𝗼𝗱𝗲 𝗦𝗻𝗶𝗽𝗽𝗲𝘁:

foreach (var followUp in followUps)
{
if (emailSent)
{
followUp.IsReminderSent = true;
followUp.User = null; // Prevent EF tracking conflict
}
}
_context.FollowUps.UpdateRange(followUps);
await _context.SaveChangesAsync();

𝗛𝗮𝘃𝗲 𝘆𝗼𝘂 𝗲𝘃𝗲𝗿 𝗳𝗮𝗰𝗲𝗱 𝗘𝗙 𝗖𝗼𝗿𝗲 𝘁𝗿𝗮𝗰𝗸𝗶𝗻𝗴 𝗰𝗼𝗻𝗳𝗹𝗶𝗰𝘁𝘀 𝗱𝘂𝗿𝗶𝗻𝗴 𝗯𝘂𝗹𝗸 𝘂𝗽𝗱𝗮𝘁𝗲𝘀? 𝗛𝗼𝘄 𝗱𝗶𝗱 𝘆𝗼𝘂 𝗵𝗮𝗻𝗱𝗹𝗲 𝗻𝗮𝘃𝗶𝗴𝗮𝘁𝗶𝗼𝗻 𝗽𝗿𝗼𝗽𝗲𝗿𝘁𝗶𝗲𝘀 𝗹𝗶𝗸𝗲 𝘁𝗵𝗶𝘀?

Top comments (0)