Reputation: 31
If a dbcontext is waited on using should one still use SaveChangesAsync() or SaveChanges() should be enough?
await using var dbContxt = new dbContxt(con);
public async Task<bool> SaveData(strig con, object data)
{
await using var dbContxt = new dbContxt(con);
var myData = new MyData
{
a = data.a,
b = data.b,
c = data.c,
};
dbContxt.MyData.Add(myData);
var result = await dbContxt.SaveChangesAsync();
return result > 0;
}
}
Upvotes: 0
Views: 64
Reputation: 1386
Short answer yes. In the scope of your async Task the DbContext will be alive.
Upvotes: 0