Answered by:
Can I use Linq in BizTalk helper components?

Question
-
I tried to use Linq to DataSet inside my BizTalk helper class, like create a query as following. There is no compile error. But the code doesn't work and I cannot set breakpoint at my query and statements after that. Why? BTSNTSvc.exe doesn't support Linq?
var query = from sku in datatable.AsEnumerable()
select (new { info = sku.Field<string>(0) + "-" + sku.Field<string>(1) + "-" + sku.Field<string>(2) });Thanks,
Cindy
Friday, March 16, 2012 10:04 PM
Answers
-
I'd guess the issue is in your component. I've never run into a part of the .NET framework I can't use within BizTalk from a .NET component. That said, there are many times when you don't need to / shouldn't.
-Dan
If this answers your question, please Mark as Answer
- Marked as answer by Leonid GanelineModerator Sunday, March 18, 2012 7:46 AM
- Unmarked as answer by s liu Monday, March 19, 2012 5:55 PM
- Marked as answer by s liu Tuesday, March 20, 2012 8:14 PM
Saturday, March 17, 2012 3:26 AM
All replies
-
Hi Cindy,
I have seen few articles that refers LINQ in BizTalk, Pls refer them below, Might give you some help.
Regarding debugging, Could you attach your BTSNTSvc.exe to VS Debugger and then try debugging it. see a blog post by Sandro here for more details.
HTH,
Naushad Alam
When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
alamnaushad.wordpress.com|
My new TechNet Wiki "BizTalk Server: Performance Tuning & Optimization"- Edited by Naushad.AlamModerator Friday, March 16, 2012 10:24 PM added more link
Friday, March 16, 2012 10:11 PMModerator -
Hi Naushad,
All these links talks about XLinq - using classes in System.Xml.Linq. So I guest BizTalk doesn't support Linq to DataSet - the classes in System.Data.DataSetEctensions - and others, like Linq to Entities.
Thanks,
Cindy
Friday, March 16, 2012 11:28 PM -
Hi Cindy,
I am curious to know why you want to use Linq inside a .NET Helper Class. What kind of functionality are you trying to implement? As debugging concerns Johan Hedberg in his LINQ in BizTalk post points out you can use DebugView. With DebugView can see what happens inside your BizTalk artefacts. You can find many sample online around BizTalk and DebugView (for instance this post I prefer). To better understand how your LINQ behaves in .NET helper class, you could also build a .NET application (Console App) to test your funtionality (this is what I usually do when implementing functionality in a .NET Helperclass for BizTalk).
HTH
Steef-Jan Wiggers
MVP & MCTS BizTalk Server 2010
http://soa-thoughts.blogspot.com/ | @SteefJan
If this answers your question please mark it accordingly
BizTalk
Friday, March 16, 2012 11:34 PMModerator -
Hi Cindy,
What is you solution environment looks like? Which version of BizTalk you are using? What you are trying to do in helper class using linq?
HTH,
Naushad Alam
When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
alamnaushad.wordpress.com |
My new TechNet Wiki "BizTalk Server: Performance Tuning & Optimization"Saturday, March 17, 2012 12:07 AMModerator -
I'd guess the issue is in your component. I've never run into a part of the .NET framework I can't use within BizTalk from a .NET component. That said, there are many times when you don't need to / shouldn't.
-Dan
If this answers your question, please Mark as Answer
- Marked as answer by Leonid GanelineModerator Sunday, March 18, 2012 7:46 AM
- Unmarked as answer by s liu Monday, March 19, 2012 5:55 PM
- Marked as answer by s liu Tuesday, March 20, 2012 8:14 PM
Saturday, March 17, 2012 3:26 AM -
I'm using BizTalk 2010 and .Net Framework 4.0. In the helper classes, there are SQL stored procedure calls and data is stored in DataSet and DataTables. That is why I tried to use Linq to DataSet to do some queries. The helper components with Linq works for Console application, but not for BizTalk orchestration. That is why I assumed Linq to DataSet doesn't work for BizTalk 2010.
Another thing I noticed that I cannot set breakpoints on the line of "var" defined in my helper component. I don't know why.
Cindy
Monday, March 19, 2012 5:30 PM -
Another thing I noticed that I cannot set breakpoints on the line of "var" defined in my helper component. I don't know why.-->are you building your project in "debug" mode? Please build it debug mode and then try. Did you try the options provided in this post by Sandro
HTH,
Naushad Alam
When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
alamnaushad.wordpress.com |
My new TechNet Wiki "BizTalk Server: Performance Tuning & Optimization"Monday, March 19, 2012 6:05 PMModerator -
Hi Cindy,
Can you post error message(s) you are getting? I wondering why it is not working in an orchestration, while it does work with console app. I am with Dan here that any part of .NET could also be used in .NET Helper Class for an orchestration. However I also think most of time you do not need a helper class with orchestration unless it is helpful (for instance for getting application configuration data). In your scenario I would just use .NET application for LINQ and not use BizTalk.
HTH
Steef-Jan Wiggers
MVP & MCTS BizTalk Server 2010
http://soa-thoughts.blogspot.com/ | @SteefJan
If this answers your question please mark it accordingly
BizTalk
Monday, March 19, 2012 6:44 PMModerator -
I use Linq to Xml all the time in my .NET helper components such as a .NET method called from a map or from an orchestration, it is much easier (and personally more fun) than the old System.Xml way of handling things. Also, Linq to Xml is nice for handling certain query-intensive tasks. I often use it to replace XSLT recursive scripting.
I wish more of the Linq capabilities were possible like in the BizTalk mapper as built-in functoids but this is not the case.
That is interesting that the breakpoint does not work on a var line, I did not know that. I would expect Linq to Datasets would work too. I know I have stepped through a .NET method running under the BizTalk service using Linq to Xml although I probably set the breakpoint on a line where I initialized my XDocument rather than the var statement.
Thanks,
If this answers your question, please use the "Answer" button to say so | Ben Cline
- Edited by Ben Cline1Moderator Monday, March 19, 2012 10:52 PM
Monday, March 19, 2012 10:48 PMModerator -
When i try to check your code, it seems that you are creating a new object.
By default (you can change the scope type if you want) all objects should be serializable when you want to call it inside the orchestration.
My suggestion is to create a Data Transfer Object and return this object in your component.
Ex:
[Serializable] public class YourDTO { public Info { get; set; } }
Then in your helper add.
public List<YourDTO> YourHelperMethod() { var result = new List<YourDTO>(); var query = from sku in datatable.AsEnumerable() select (new { info = sku.Field<string>(0) + "-" + sku.Field<string>(1) + "-" + sku.Field<string>(2) }); foreach(var i in query) { result.Add( new YourDTO { Info = i.Info } ); } return result; }
Note: I'm returning a list, I'm not sure whetherin orchestration it would support a generic List. The way i normally do it, is to create a schema with multiple result node then use XSD.exe to generate the class, then return that object instead. Then for the message type i would use the schema.
Also, found an old article returning generic to be used in orchestration:
http://blog.andrewrivers.co.uk/2009/11/use-of-generic-types-in-biztalk-and.html
Randy Aldrich Paulo
MCTS(BizTalk 2010/2006,WCF NET4.0), MCPD | My Blog
BizTalk Message Archiving - SQL and File
Automating/Silent Installation of BizTalk Deployment Framework using Powershell >
Sending IDOCs using SSIS
- Edited by Randy Paulo Tuesday, March 20, 2012 12:23 PM
- Proposed as answer by Shailesh Kawade Tuesday, March 20, 2012 1:06 PM
Tuesday, March 20, 2012 12:14 PM -
As Dan Rosanova said, the issue is in my component. I fixed my component and it worked.
Thank everyone's helpful suggestions!
Cindy
Tuesday, March 20, 2012 8:13 PM