Why does EF(4.0) take so long to insert rows into a table? When i queried the data just after closing the application, it returned some 20,000 rows and later on I noticed, though the app was closed the data was not done inserting and the insertions were happening in the background. Why is this? What are the ways to inform the application (I am planing to run these inserts as a windows service since they are long-running) that the inserts are really completed? What are the ways to increase the speed of these inserts? I just have one foreign key relationship..so it is not a very complex data model as well. Thanks for any help!
The application is ASP.Net application. Here is the piece of code where I am calling the SaveChanges()
.
do
{
if (token != null)
{
response = context.Execute<NetflixService.Title>(token)
as QueryOperationResponse<NetflixService.Title>;
}
using (Models.MovieContext movieCtxt = new Models.MovieContext())
{
foreach (var item in response)
{
IList<Models.MovieGenre> genres = new List<Models.MovieGenre>();
foreach (var genreIterator in item.Genres)
{
var genre = new Models.MovieGenre
{
Genre = genreIterator.Name
};
genres.Add(genre);
}
//genres.Add(new Models.MovieGenre { Genre = "filmy" });
var movie = new Models.MovieCatalog
{
MovieTitle = item.Name,
MovieGenres = genres
};
movieCtxt.MovieCatalogs.Add(movie);
}
movieCtxt.SaveChanges();
}
}
while ((token = response.GetContinuation()) != null);