views:

22

answers:

1

I'm building ASP.Net MVC2 application on top of a legacy database. Every table in the database includes an id that defines to what organization it belongs to. Like:

| id | name | org_id |
|  1 | John |  4     |
|  2 | Joe  |  4     |
|  3 | Anne |  2     |

Now, user "John" should not see Anne from another organization e.g. get that row from the database, ever. My model would be something like this

[Table(Name="person")]
public class Person
  [Column] public int id { get; set; }
  [Column] public string name { get; set; }

org_id is not included to the model because it really isn't domain model in that sense. It is there just to filter results (and eventually cascade organization deletes in the database).

I have a repository class that returns IQueryable<Person> using DataContext.GetTable<Person> and thus enables lazy loading.

How can I insert to that IQueryable or to the DataContext custom Where-clause that would require the org_id to be 4. Writing

return (new DataContext(connectionString)).GetTable<CardBase>().Where(x => x.NOORGIDHERE...

results only filtering by proerties from the Person-class.

A: 

Either use a stored procedure, or map that column as read-only (and perhaps internal, so you can create a wrapper for it, without exposing the property).

leppie
Thanks for the tip! I did it with `internal` keyword. That way I can also name the org_id columns (they variate in the database tables). Problem solved.
Juho Rutila