Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use table hints in Linq to sql

how to use table hints in Linq to sql when call submit changes method

dataContext.table2.something = dataContext.table1.something;
dataContext.SubmitChanges();    

i want to use it like this sql code:

declare @var int;
begin transaction
select @var = something from table1 with (HoldLock);
update table2 set something = @var;
update table1 set something = @var + 1;
commit transaction;
like image 889
Alaa Jabre Avatar asked Mar 31 '12 20:03

Alaa Jabre


2 Answers

This is not possible.

Actually, it is possible by doing serious nasty hacking using reflection. You can compile a query, and then fiddle with the generated SQL string in some internal object. This is the least desirable way to do this.

I recommend you stay with raw SQL for this one.

like image 63
usr Avatar answered Oct 01 '22 03:10

usr


I've always heard that cant be done. Linq's goal (or at least one of them) is take or mind out of SQL so you dont have to worry with things like this. I suggest that you add your code with the table hint to a SQL procedure and use Linq to call it.

like image 21
Diego Avatar answered Oct 01 '22 04:10

Diego