views:

38

answers:

0

Hi guys I have to model the following situation. I came up with 2 possible alternatives, but I want to know if there's a better solution.

Here's the deal...

Simplified Schema

User              Group
-----------       ------------
UserId (PK)       GroupId (PK)
Name              Name
...               ...

       \           /
          UserGroup
         -------------
          UserId (FK)
          GroupId (FK)

This is simple. A table for Users, a table for Groups and then a table for relating users to group (many-to-many)

Then I have other entities (ie. Articles) that can be owned by both User and Groups (can be owned by one User, or can be owned by one Group, or can be owned by a User AND a group, etc).

So here's the deal. I could do:

A

Article                ArticleOwnership
--------------         ----------------
ArticleId (PK)  <----- ArticleId (FK)
Title                  UserId (FK-NULLABLE)
...                    GroupId (FK-NULLABLE)

The thing here is that when I want to check if a particular user owns a particular article, seems I have to check for both. This is easy using T-SQL, but I want to use Entity Framework (never used an ORM before, so be nice xD).

How would you model this situation???

Another approach might be:

B

Create a group for every user, containing inside just that user and manage the ownerships only by groups. How does this sound for you?

Thanks to all and sorry if my explanation is not very clear, my english is not perfect.