© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
3 replies
clever_cottonmouth

I am trying to store data in database using EF my code run fine but its not storing data

if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
var jsonObject = JsonConvert.DeserializeObject<JToken>(json);
if (jsonObject != null && jsonObject.HasValues)
{
List<Initiative_Goal> ahaInitiative = jsonObject["initiatives"].
Select(x =>
{
Initiative_Goal initiative = new Initiative_Goal();

initiative.InitiativeID = x.Value<long>("value");

return initiative;
}).ToList();

foreach (Initiative_Goal initiatives in ahaInitiative)
{
var existingRecord = await context.Initiative_Goal.FirstOrDefaultAsync(x => x.InitiativeID == initiatives.InitiativeID);

if (existingRecord == null)
{
fullAPIList.Add(initiatives);
}
else
{
existingRecord.InitiativeID = initiatives.InitiativeID;

//existingRecord.Description = initiatives.Description;
}
}

await context.SaveChangesAsync();
}
else
{
Console.WriteLine("No Aha data found in the response.");

}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ I am trying to run my first C# code but it’s not working
C#CC# / help
3y ago
Not able to store data in database
C#CC# / help
2y ago
Run EF Migrations in Azure SQL Database
C#CC# / help
2y ago
Why does Ef Core not save my data in the database?
C#CC# / help
17mo ago