So basically I have an application that works with just one user, but I’d like to make it multi-user. This would involve me logging a user in, and keeping the user ID in session, plus adding a user id column to my database tables. no biggy.
I’d like to change my dbml, or use it’s partial, so that any query I throw through it also gets
.WHERE(user=>user.id=MYPARAM)
added to it, to return just records for the logged in user.
Is there a quick win to be had? A single place where I can specify this in the .dbml?
I would perhaps create a lambda expression dynamically.
The Where clause takes an object of type Expression>
You can then create an expression using the following.
Then
You would then create an expression for u.id = ‘test’ by using a binary expression.
and then attaching it to the Expression as follows:
In effect this is building a lambda expression u=> u.id = ‘test’
The func object can then be used in the .Where as follows: .Where(func)
Obviously, you can dynamically build this to any criteria you need at any time in your application.