views:

240

answers:

2

I am involved in development of a tiered application that uses LINQ2SQL separated from the web server with a NET.TCP Binding on WCF.

My questions are:

  1. What sort of measures should I take to achieve the best performance?
  2. Since the entity objects returned by the LINQ need to be converted to a IEnumerable list to be serialized everytime, is there anyway to remove this dependency?
+1  A: 

1) Concentrate on a properly normalized database design. I would say that when you are forced to make design tradeoffs in your code vs. database design, if performance is your goal, make tradeoffs in your object design instead of your database design. Understand that you aren't going to be able to do a proper supertype/subtype database design which will work with Linq to SQL (I'm told you need to use the EF instead).

2) Depends what you mean here. If you're asking how you would serialize anonymous classes across the wire, the easy answer is: "you can't, so don't try". If you want to put lists of objects across the wire, just use the ToArray() extension method on your IEnumerable collections to ship arrays of your business objects over the wire.

Dave Markle
I compared ToArray with ToList in a small test, and I found ToArray slower. So currently I am using ToList but since you mentioned this now I am getting doubts. I will recheck this. I am not using any anonymous types, and everything is in the form of a LINQ entity or IEnumerable<LINQENTITY>.
Syed Sajid Nizami
A: 

Linq to SQL is very slow unless you compile queries. Otherwise your application will be CPU bound as most of the time will be spend converting Expression trees into SQL.

We are talking about 10x performance gain if you use compiled queries. Try it :)

bh213