Hi Folks,
Whenever i tried using query expression for retrieve multiple operations, came to know some interesting facts which exists and hence would like to share with you all.
As you already know Query expression was used when dealing with a little complex query, lets see this in action
Basic Query Expression Example
// Query using ConditionExpression and FilterExpression |
ConditionExpression condition1 = new ConditionExpression(); |
condition1.AttributeName = "lastname"; |
condition1.Operator = ConditionOperator.Equal; |
condition1.Values.Add("Brown"); |
FilterExpression filter1 = new FilterExpression(); |
filter1.Conditions.Add(condition1); |
QueryExpression query = new QueryExpression("contact"); |
query.ColumnSet.AddColumns("firstname", "lastname"); |
query.Criteria.AddFilter(filter1); query.NoLock = true;//Condition to prevent occurrence of deadlocks, distinct was used to retrieve unique columnsets in the query |
EntityCollection result1 = _serviceProxy.RetrieveMultiple(query); |
The benefit of setting NoLock
to true
is that it allows you to keep the system from issuing locks against the entities in your queries; this increases concurrency and performance because the database engine does not have to maintain the shared locks involved. The downside is that, because no locks are issued against the records being read, some “dirty” or uncommitted data could potentially be read. A “dirty” read is one in which the data being read is involved in a transaction from another connection. If that transaction rolls back its work, the data read from the query using NoLock
will have read uncommitted data. This type of read makes processing inconsistent and can lead to problems. The risk of having “dirty” data is something to consider, especially in high database transaction environments.
Reference: https://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.query.queryexpression.aspx
No comments:
Post a Comment