public static Product GetProduct(IOrganizationService ser, Guid productid, ColumnSet columnset)
{
try
{
QueryExpression query = GetQueryExpressionSingle("product", "productid", productid, columnset);
EntityCollection ec = ser.RetrieveMultiple(query);
if (ec != null && ec.Entities.Count == 1)
return (Product)ec.Entities[0];
else
return new Product();
}
catch (Exception ex)
{
FileLogHelper.LoggEx(ex, typeof(CrmManagerStatic), "public static Product GetProduct(IOrganizationService ser,Guid productid,ColumnSet columnset)" + Environment.NewLine +
"ProductId :" + CommonFunction.ToString(productid));
throw ex;
}
}
GetQueryExpressionSingle
public static QueryExpression GetQueryExpressionSingle(string entityName, string attributeName, object values, ColumnSet columnSet)
{
QueryExpression query = new QueryExpression()
{
EntityName = entityName,
ColumnSet = columnSet,
Criteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions = { new ConditionExpression(attributeName, ConditionOperator.Equal, values) }
}
};
return query;
}
RetrieveMultipleQuery
public static EntityCollection RetrieveMultipleQuery(IOrganizationService crmService, QueryExpression query)
{
try
{
EntityCollection ec = null;
ec = crmService.RetrieveMultiple(query);
if (ec != null && ec.Entities.Count != 0)
return ec;
else
return new EntityCollection();
}
catch (Exception ex)
{
FileLogHelper.LoggEx(ex, typeof(CrmManagerStatic), "public EntityCollection RetrieveMultipleQuery(QueryExpression query)"+Environment.NewLine+
"EntityName : " + query.EntityName);
throw ex;
}
}
Hiç yorum yok:
Yorum Gönder