tags:

views:

39

answers:

1

HI ,

I am going to rewrite a store procedure in LINQ.

What this sp is doing is joining 12 tables and get the data and insert it into another table.

it has 7 left outer joins and 4 inner joins.And returns one row of data.

Now question. 1)What is the best way to achieve this joins in linq. 2) do you think this affect performance (its only retrieving one row of data at a given point of time)

Please advice.

Thanks SNA.

A: 

You might want to check this question for the multiple joins. I usually prefer lambda syntax, but YMMV.

As for performance: I doubt the query performance itself will be affected, but there may be some overhead in figuring out the execution plan, since it's such a complicated query.
The biggest performance hit will likely be the extra database round trip you will need compared to the stored procedure. If I understand you correctly, your current SP does the SELECT AND INSERT all at once. Using LINQ to SQL or LINQ to Entities, you will need to fetch the data first before you can actually write them to the other table.

So, it depends on your usage if rewriting is warranted. Alternatively, you can add stored procedures to your data model. It will be exposed as a method on your data context.

Thorarin