I am sure there is a way to use bulk insert/update something like UPDATE ON DUPLICATE, this way I can save time since the files I get are huge and bulk insert/update is known to have better performance. I would like to avoid the iteration I am now using.
insertall doesn't work for already stored rows, I need the combination of both update and insert
Here is my code, Your help is highly appreciated.
Expand|Select|Wrap|Line Numbers
- foreach (Profile tmpProfile in profiles)
- {
- try
- {
- var matchedProfile = (from c in db.ProfileEntities
- where c.ProfileId == tmpProfile.Id
- select c).SingleOrDefault();
- if (matchedProfile == null)
- {
- //Insert
- db.ProfileEntities.InsertOnSubmit(EntityMapper.ToEntity(tmpProfile));
- }
- else
- {
- //Update
- EntityMapper.ToEntity(ref matchedProfile, tmpProfile);
- }
- }
- catch (System.Data.SqlServerCe.SqlCeException sqlExec)
- {
- }
- catch (Exception e)
- {
- }
- }
- db.SubmitChanges();