Ev.
Ev.

Reputation: 7589

How to persist a change in a DBML

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

Upvotes: 1

Views: 241

Answers (1)

Matt Sherman
Matt Sherman

Reputation: 8358

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.

Upvotes: 2

Related Questions