tags:

views:

26

answers:

1

I have a table of users called Users

And a view called UsersActive that filters out deactivated users.

When I create my DBML, I drag the Users table in, then I change the property on the table to point to UsersActive.

This works well, until the DBML gets re-created.

Does anyone know how to fix this?

I've tried overriding the

[Table(Name="dbo.Users")]

attribute in a partial class but get the error:

Duplicate 'Table' attribute

Does anyone know how to go about this?

Thanks in advance!

-Ev

+2  A: 

You should just be able to add the View to the DBML, just like a table...yes?

Update: No, it will probably not maintain the relationships -- views don't have relationships.

It sounds like your goal is to query active users in a simple way, without having to specify the criterion in each query?

What you might do then is to have a repository class with a method of GetUsers(). That method does the Linq query and ensures that the active criterion is always there.

Perhaps the method would have a signature of Respository.GetUsers(bool includeDeativated = false). Calling GetUsers() without arguments will not return deactivated, but you can override it if desired.

Matt Sherman
But will this maintain the relationships?
Ev
Updated above...
Matt Sherman
Thanks Matt, I'll give that a go.
Ev