How to intercept and modify SQL query in Linq to SQL

前端 未结 4 1278
礼貌的吻别
礼貌的吻别 2021-02-04 15:04

I was wondering if there is any way to intercept and modify the sql generated from linq to Sql before the query is sent off?

Basically, we have a record security layer,

4条回答
  •  遥遥无期
    2021-02-04 15:18

    Try setting up a view in the DB that applies the security filter to the records as needed, and then when retrieving records through L2S. This will ensure that the records that you need will not be returned.

    Alternatively, add a .Where() to the query before it is submitted that will apply the security filter. This will allow you to apply the filter programmatically (in case it needs to change based on the scenario).

提交回复
热议问题