How to use table hints in Linq for sql

how to use table tips in Linq to sql when calling the comment 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; 
+6
source share
2 answers

I have always heard that this is impossible to do. Linq's goal (or at least one of them) is to take or understand SQL, so you donโ€™t have to worry about that. I suggest you add your table hint code to the SQL procedure and use Linq to call it.

+1
source

It's impossible.

In fact, this can be done by doing a serious nasty hack using reflection. You can compile the query and then script with the created SQL string in some internal object. This is the least desirable way to do this.

I recommend you stay with raw SQL for this.

+2
source

Source: https://habr.com/ru/post/912135/


All Articles