Hi all
i am using .NET freamwork 4.0.
and i am also using ADO.Net Entity Data modal for database operation
my question on Parellel Library in Net framework 4.0
i want to save the list of pateint object using ADO.Net Entity Data modal but not using normal loop.
i want to use the Parallel loop that are in .Net framework 4.0
i will give some examples as below
// Using Normal Loop
private void SavePatients(List<Patient> p)
{
using (PatientEntities context = new PatientEntities())
{
for(int i=0; i< p.Count(); i ++)
{
context.AddToPatients(p.ElementAt<Patient>(i));
context.SaveChanges();
}
}
}
//Using Parallel Loop
private void SavePatients(List<Patient> p)
{
using (PatientEntities context = new PatientEntities())
{
Parallel.For(0, p.Count(), i =>
{
context.AddToPatients(p.ElementAt<Patient>(i));
context.SaveChanges();
});
}
}
when i use the normal loop it will perfectly working fine
but when i use the parallel loop the it will give the error as below
The type 'PatientEntities.Data.Entity.Patient' has been mapped more than once.
can anybody pls help me.....
Advance Thanks
Have Nice Time....