在MS CRM Development Environment实例中创建了一千条记录。需要一个新字段,并由实体自定义创建。我们需要该字段中每条记录的随机值。有什么支持的方法来实现这个目标?
我想到的选项是
答案 0 :(得分:0)
使用CRM连接器的LinqPad 4中的以下解决方案需要10分钟来处理大约700条记录。
//set up a random amount generator
var r = new Random();
//initialte with an arbitrary value
decimal amount = 13;
//list all required records using linq
var ats = (from at in psm_assettypeSet
where at.psm_Amount.Equals(null)
select at).ToList();
//check count
ats.Count().Dump();
//check
(ats.First() as psm_assettype).psm_Amount.Dump();
//loop through
foreach (psm_assettype at in ats)
{
//calculate amount
amount = (decimal)r.Next(31);
//check
amount.Dump();
//set amount, use XRM class properly
at.psm_Amount = new Microsoft.Xrm.Sdk.Money(amount);
//update object in memory
UpdateObject(at);
}
//bulk update all records
SaveChanges();
//check success
(ats.First() as psm_assettype).psm_Amount.Value.Dump();