我是 CRM 2011 插件的新手。在这里,我是一段引发错误的代码:
private static void AddWRItoServiceActivity(IOrganizationService service, Guid id)
{
using (var crm = new XrmServiceContext(service))
{
var serviceactivity = crm.ServiceAppointmentSet.Where(c => c.Id == id).First();
var serviceitem = crm.brd_serviceitemSet.Where( c => c.brd_RegardingServiceId == serviceactivity.ServiceId);
for (int i = 1; i < serviceitem.Count(); i++)
{
var workReportItem = new brd_workreportitem
{
brd_name = "By payman Plugin",
brd_serviceappointment_brd_workreportitem = serviceactivity,
};
crm.AddObject(workReportItem);
crm.SaveChanges();
}
}
}
我试过这个:
for (int i = 1; i < serviceitem.ToList().Count(); i++)
这也给出了错误。您能帮我计算一下这样的数还是使用其他语法(例如 foreach)?PS:我也试过这个:
foreach (var s in serviceitem.ToList())