What could be the best preferable way of returning back a modified list grabbed from an Entity Framework to our database.
Question In a simpler form :
How to return a Custom List e.g List of about 100,000 records to the database
these are the modified version of our entities in an offline Thread-safe manner.
The Code :
var query = From context.Products
select p;
var listQuery = query.ToList();
Edit : Seems that all the attached Lists to Entities will cause Thread-Safety errors.
So we have to make a cloned version of the list, something like List
and after edition insert all the items in a regular time-consuming or a shorthand way,
Any Ideas ?
Sample Steps :
- Make and fill an Custom List Array of our defined type from an entity DataContext
- Iterate through the List ( about 100,000 items)
- Edit the List
- Finally Return it back to the database
How to pass listQuery to the database ?
Iterating through each of them and find the equivalent entity or record via Entity/Linq and change the item ?? could it be the best idea or do we have any shorthand or best practice doing this ?
Any suggestion or idea ?
First, there is a slight error in your code example. You need to add ‘from p in context.Products’ rather than ‘from context.Products’
If I am understanding correctly, the way i typically edit a list of records is:
I prefer to use method syntax. If you prefer to use query syntax, you can replace the first line with: