SubSonic generated code and always filtering records
Posted
by cmroanirgo
on Stack Overflow
See other posts from Stack Overflow
or by cmroanirgo
Published on 2010-04-28T06:31:02Z
Indexed on
2010/04/28
6:43 UTC
Read the original article
Hit count: 329
subsonic-active-record
|subsonic
Hi,
I have a table called "Users" that has a column called "deleted", a boolean indicating that the user is "Deleted" from the system (without actually deleting it, of course).
I also have a lot of tables that have a FK to the Users.user_id column. Subsonic generates (very nicely) the code for all the foreign keys in a similar manner:
public IQueryable<person> user
{
get
{
var repo=user.GetRepo();
return from items in repo.GetAll()
where items.user_id == _user_id
select items;
}
}
Whilst this is good and all, is there a way to generate the code in such a way to always filter out the "Deleted" users too?
In the office here, the only suggestion we can think of is to use a partial class and extend it. This is obviously a pain when there are lots and lots of classes using the User table, not to mention the fact that it's easy to inadvertently use the wrong property (User vs ActiveUser in this example):
public IQueryable<User> ActiveUser
{
get
{
var repo=User.GetRepo();
return from items in repo.GetAll()
where items.user_id == _user_id and items.deleted == 0
select items;
}
}
Any ideas?
© Stack Overflow or respective owner