Quantcast
Channel: CRM Development 論壇
Viewing all articles
Browse latest Browse all 10280

The best way to update a field.

$
0
0
I would like to update the testfield value on all records of the testEntity to "updated"
Which do you think is the best way?

Case1:

var testEntities = context.CreateQuery<new_testentity>().Select(r => new { 
    r.Id,
    r.testfield
});

foreach (var record in testEntities)
{
    var testEntity = context.GetAttachedEntities().First();
    testEntity.testfield = "updated";
    context.UpdateObject(testEntity);
    context.SaveChanges();
}




Case2:

var testEntities = context.CreateQuery<new_testentity>(); foreach (var record in testEntities) { context.Detach(record); var testEntity = new testEntity(); testEntity.testfield = "updated"; testEntity.Id = record.Id; context.Attach(testEntity); context.UpdateObject(testEntity); context.SaveChanges(); }




Case3:

var testEntities = context.CreateQuery<new_testentity>().ToList();
context.Detach(testEntities);
foreach (var record in testEntities)
{
    var testEntity = new testEntity();
    testEntity.testfield = "updated";
    testEntity.Id = record.Id;
    context.Attach(testEntity);
    context.UpdateObject(testEntity);
    context.SaveChanges();
}




Taichi,Sato




Viewing all articles
Browse latest Browse all 10280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>