2016-06-23 4 views
0

Я пытаюсь получить все встречи из нашей онлайн-среды CRM, используя запрос LINQ (я новичок с программированием). Получение данных о назначении легко выполняется, но я также хочу получить требуемых участников для встреч (это может быть учетная запись, например, контакт) и получить некоторые метаданные (например, имя, адрес электронной почты, например) от участников. К сожалению, это невозможно сделать, и я надеялся, что кто-то поможет мне в этом.Dynamics CRM 2016 (Online) - Получить встречи

public AppointmentData[] RetrieveActivities(bool persistChange) 
    { 
     var appointmentData = new List<AppointmentData>(); 

     using (var context = new FmServiceContext(_service)) 
     { 
      var appointments = (from app in context.AppointmentSet 
       join a in context.AccountSet on app.Account_Appointments.AccountId equals a.AccountId 
       where app.StateCode != 0 
       select new {app, a}); 


      foreach (var apappointments in appointments) 
      { 
       appointmentData.Add(new AppointmentData 
       { 
        //this should be the list of required attendees 
        RequiredAttendees = new ActivityParty[] 
        { 
         Attendeename = apappointments.a.Name 

        }, 
        //Appointment data 
        AppointmentType = apappointments.app.fm_Typeafspraak == null ? null : DataHelper.GetOptionSetValueLabel(apappointments.app.LogicalName, "fm_typeafspraak", apappointments.app.fm_Typeafspraak.Value, _service), 
        Subject = apappointments.app.Subject, 
        StartDate = apappointments.app.ScheduledStart, 
        EndDate = apappointments.app.ScheduledEnd, 
        Duration = apappointments.app.ScheduledDurationMinutes, 
        Location = apappointments.app.Location, 
        Description = apappointments.app.Description, 
        Priority = apappointments.app.PriorityCode == null ? null : DataHelper.GetOptionSetValueLabel(apappointments.app.LogicalName, "prioritycode", apappointments.app.PriorityCode.Value, _service), 
        Status = apappointments.app.StateCode.ToString() 
       }); 
      } 

     } 
     return appointmentData.ToArray(); 
    } 

ответ

0

Я не думаю, что вам нужно объединение, как деятельность партии иды уже есть в вашем запросе .. Вы можете ударять ограничение в присоединиться к функциональности здесь. Вот подход:

foreach(var app in appointments) 
{ 
    var requiredAttendees = app.RequiredAttendees.ToList(); 

    foreach(var ra in requiredAttendees) 
    { 
     // do whatever you want with each required attendee here, perform a separate retrieve for more details 

    } 
} 

Также я признаю, что это дополнительный шаг. Если вы хотите попытаться подключиться к работе, я бы рекомендовал пойти против вечеринки. Если вы собираетесь идти по этому маршруту, вам может понадобиться вложенный запрос или более сложное соединение, так как отношение к ActivityParty равно 1: N. Проверьте эту ссылку, если вы заботитесь только о первом требуемом посетителе: https://www.periscopedata.com/blog/4-ways-to-join-only-the-first-row-in-sql.html

0

Решила! Я использовал подход Брендона, чтобы сделать это. Во-первых переспросила я все назначения,
Вот мой код:

public AppointmentData[] RetrieveAppointments(bool persistChange) 
    { 
     var appointmentData = new List<AppointmentData>(); 


     using (var context = new FmServiceContext(_service)) 
     { 
      //First we get all relevant appointments 
      var appointments = (from app in context.AppointmentSet 
           where app.StateCode != 0 
           select new { app}); 


      foreach (var appointment in appointments) 
      { 
       //we loop all the returned attendees of the appointments 
       var attendees = new List<Attendee>(); 
       foreach (var attendee in appointment.app.RequiredAttendees) 
       { 
        if (attendee.PartyId != null) 
        { 
         //if an attendee is an account 
         if (attendee.PartyId.LogicalName == "account") 
         { 
          var account = (from acc in context.AccountSet 
           where acc.AccountId == attendee.PartyId.Id 
           select new {acc}); 
         } 

         //add the attendee 
          { 
          attendees.Add(new Attendee 
          { 

           // get additional metadata of the attendee 
          }); 
         } 
         appointmentData.Add(new AppointmentData 
       { 
        Attendees = attendees, 
        // get additional metadata of the appointment 
       }); 
        } 
       } 
      } 
      return appointmentData.ToArray(); 
     } 
    } 
} 

Результат: список назначений с перечнем необходимых участников для этого назначения.

Смежные вопросы