22 Şubat 2013 Cuma

CRM 4.0 - QUERY EXPRESSION (Link Entity Kullanımı)


public static BusinessEntityCollection FiyatKarsilastirmaTalebiBolgeleriniGetir(CrmService crmservice, Guid fiyatkarsilastirmatalebiid)
    {
      try /*CodeLibrary00*/
      {
        ConditionExpression sart = new ConditionExpression() { AttributeName = "new_fiyatkarsilastirmatalebiid", Operator = ConditionOperator.Equal, Values = new object[] { fiyatkarsilastirmatalebiid } };
        LinkEntity link1 = new LinkEntity()
        {
          LinkFromEntityName = "new_bolge",
          LinkFromAttributeName = "new_bolgeid",
          LinkToEntityName = "new_new_fiyatkarsilastirmatalebi_new_bolge",
          LinkToAttributeName = "new_bolgeid"
        };

        LinkEntity link2 = new LinkEntity()
        {
          LinkFromEntityName = "new_new_fiyatkarsilastirmatalebi_new_bolge",
          LinkFromAttributeName = "new_fiyatkarsilastirmatalebiid",
          LinkToEntityName = "new_fiyatkarsilastirmatalebi",
          LinkToAttributeName = "new_fiyatkarsilastirmatalebiid",
          LinkCriteria = new FilterExpression()
          {
            FilterOperator = LogicalOperator.And,
            Conditions = new ConditionExpression[] { sart }
          }
        };

        link1.LinkEntities = new LinkEntity[] { link2 };

        QueryExpression query = new QueryExpression()
        {
          EntityName = "new_bolge",
          ColumnSet = new ColumnSet() { Attributes = new string[] { "new_bolgeid" } },
          LinkEntities = new LinkEntity[] { link1 }
        };

        BusinessEntityCollection businessEC = null;

        businessEC = crmservice.RetrieveMultiple(query);

        if (businessEC != null && businessEC.BusinessEntities != null)
        {
          if (businessEC.BusinessEntities.Length != 0)
            return businessEC;
          else
            return new BusinessEntityCollection();
        }
        else
        {
          return new BusinessEntityCollection();
        }

      }
      catch (Exception ex)
      {
        CodeLibrary.HataMesajiEkle(codeLibrary_Exceptions, "CodeLibrary00", ex.Message);
        return new BusinessEntityCollection();
      }
    }

Hiç yorum yok:

Yorum Gönder