本篇文章主要介绍了" SQL Queries from Transactional Plugin Pipeline",主要涉及到方面的内容,对于企业开发感兴趣的同学可以参考一下:
Sometimes the LINQ, Query Expressions or Fetch just doesn't give you the ability...
Sometimes the LINQ, Query Expressions or Fetch just doesn't give you the ability to quickly query your data in the way you want to. A good example of this is the lack of left outer join support if you want a where clause to filter results based on the joined entity. Sometime, you just need to query your database using good old T-SQL. In CRM 4 you could do this fairly easily by simply opening a connection directly and doing what you need to.
Since Transactional Pipelines were introduced with CRM2011 , I've been dancing a jig every time I don't have write manual rollback compensation code – but – if you try a SQL query from a transactional pipeline that queries the same entity that you are updating/inserting, you'll get a blocking lock that will cause the operation to time out.
To get around this, you have a number of options:
1) Call the SQL from outside a transaction in the PreValidation or an Async Pipeline
2) Use the following method to hook into the CRM Transaction and execute your query from within that.
Note: I should say that this could be considered breaking the following rule in the SDK that defines what is supported or not:
"The use of application programming interfaces (APIs) other than the documented APIs in the Web services DeploymentService, DiscoveryService, Organization Data Service, SOAP endpoint for Web Resources and OrganizationService."
I'm assuming that you are familiar with the System.Data library, so I'm just posing how to get a SqlTransaction, and you can do the rest: