views:

6

answers:

0

I have such stored proc in my db which doing this:

        UPDATE SomeTable
        SET SomeId = SomeNewId
        WHERE Id IN 
        (
         SELECT TOP 100 Id

         WHERE Id IN 
          (
              SELECT Id FROM SomeTable WHERE SomeColumn IS NOT NULL
         )
        )
        SELECT @@Rowcount AS 'RowCount'

I did import this query as a function in Entity Framework. All working well.

But the question is, is there any ways of generate such query using Linq expression

I am using repository pattern and if I live it like it is will be evil, because is breaking the design.

From another hand I have method which returns 'IQueryable' I know how to do the same using this method, but it is required more than one request to database. I may run query to request the top number of Id's and then I may update each entity from returned result.... But in such case there is another evil, I don't want to query database so many times.

Is there any ways of minimize the number of queries using linq expression?

Any suggestions?

In such case I prefer the first evil, I think that better to break the design rather than break performance.