Im trying to add some dummy content into my database. I have a sample object called "obj", and I'm using a for loop to insert data like the code below:
public async Task<Post> Add(Post obj)
{
if (db != null)
{
obj.Id = 0;
for (int i = 0; i < 100; i++)
{
await db.Post.AddAsync(obj);
}
await db.SaveChangesAsync();
return obj;
}
return null;
}
However, it does add only 1 record into database, could you please explain what's wrong here?
objshould be inserted (while one time tends to be enough for the poor thing). Instead different instances should be inserted, so you have to create them in the loop.