0

在 MS CRM 开发环境实例中创建了一千条记录。新字段是必需的,由实体自定义创建。我们需要该字段的每条记录中的随机值。实现这一目标的支持方法是什么?

我想到的选项是

  1. 工作流程(不允许随机值)
  2. 批量更新(不允许随机值)
  3. 添加填充有 =RAND() 的随机值列后,从 excel 导入批量更新。不确定这是否会更新现有记录。
  4. 编写一个 ODATA Web 资源 html 页面来执行此操作。(太脆弱,开发调试费时费力)
  5. 使用带有 CRM 2011 连接器插件的 LinqPad 4 来实现相同的效果
4

1 回答 1

0

The following solution in LinqPad 4 with CRM connector took 10 minutes to process around 700 records.

//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();
于 2013-07-12T02:35:45.757 回答