Tuesday, April 28, 2009

Retrieve Multiple Dynamic Entity Records Example

Example:





try      
{
BusinessEntityCollection retrieved = RetreiveMultipleEntityDetails(entityName.Trim().ToLower(), new string[] { filterColumn }, new string[] { filterValue }, null);            if (retrieved != null)                  return (DynamicEntity)retrieved.BusinessEntities[0];            return null;      }
 
Function: 
 
 
 
public BusinessEntityCollection RetreiveMultipleEntityDetails(string entityName, string[] filterColumns, string[] filterValues, string[] ColumnList)        
{
RetrieveMultipleResponse retrieved = new RetrieveMultipleResponse();
try
{
/// Create the query object.
QueryByAttribute query = new QueryByAttribute();
query.EntityName = entityName.Trim().ToLower();
if (ColumnList == null)
{
query.ColumnSet = new AllColumns();
}
else
{
ColumnSet columns = new ColumnSet();
columns.Attributes = ColumnList;
query.ColumnSet = columns;
}
query.Attributes = filterColumns;
query.Values = filterValues;
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
retrieve.Query = query;
retrieve.ReturnDynamicEntities = true;
 
retrieved = (RetrieveMultipleResponse)Service.Execute(retrieve);
if (retrieved != null)
return retrieved.BusinessEntityCollection;                return null;
}
#region Exception Handling
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new Exception(ex.Detail.InnerText);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
#endregion Exception Handling
}

2 comments:

Anonymous said...

Where is this ColumnList from?

Anonymous said...

it is a parameter in the method call above