Im a newcomer to CRM 2011 plugins. Here, I is a piece of my code which throws error:
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();
}
}
}
I've tried this:
for (int i = 1; i < serviceitem.ToList().Count(); i++)
and this gives error also. Would you please help me with counting such as this or using other syntax such as foreach? P.S.: I've tried this also:
foreach (var s in serviceitem.ToList())
XrmServiceContext
your early bound classes? - James Wood