我是CRM 2011插件的新成員。在這裏,我是一塊我的代碼會拋出錯誤:適用於多實體創建的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? P.S:我已經試過這也:
foreach (var s in serviceitem.ToList())
你的錯誤是什麼? –
不支持「計數」方法。 –
你試過這個嗎? foreach(var in serviceitem) –