- MSCRM record count
- Posted by StingRayYellow on September 11th, 2006
I have a SQL query that searched my products based on a product number. My
goal is to see if the product exists, and set a BOOL value accordingly. My
code (listed below) does work, but it seems a bit inefficient for what I want
to accomplish.
I’m looking for the equivalent to a COUNT statement.
Any suggestions?
QueryExpression query = new QueryExpression();
query.EntityName = EntityName.product.ToString();
ColumnSet productColumns = new ColumnSet();
productColumns.Attributes = new string[] { "productnumber" };
query.ColumnSet = productColumns;
ConditionExpression newConditions = new ConditionExpression();
newConditions.AttributeName = "productnumber";
newConditions.Operator = ConditionOperator.Equal;
newConditions.Values = new object[] { reader.Value };
FilterExpression filter = new FilterExpression();
filter.Conditions = new ConditionExpression[] { newConditions };
query.Criteria = filter;
BusinessEntityCollection retrieved = service.RetrieveMultiple(query);
bool UpdateFlag = false;
foreach (product prod in retrieved.BusinessEntities)
{
Console.WriteLine(prod.productnumber);
UpdateFlag = true;
break;
}
if (UpdateFlag)
- Posted by Rich Reynolds on September 12th, 2006
if you prefer you could use the filtered views (filteredproduct) which means
you can access the sql server directly and therefore use normal SQL statement.
Accessing the db directly is supported for filtered views.
hth.
- Posted by StingRayYellow on September 15th, 2006
Yes, that works.
Thank you.