Itzik, thank you very much for your help.  Still have a couple more
questions.

1. Since this is another many to many.  Do I need to add

 public virtual IList<User> Favorites { get; set;}

in Post class?

2.  if I decide to modify my Favorite table a little bit

Favorite Table:
-----------------------------------------------------
Id: int (PK)
UserId: int  (FK)
PostId: int  (FK)
IsPublic: bool
CreateDate: DateTime

Now I add 3 more fields in the database.  I have to create a class for
favorite.  here's my code, please let me know if I am doing it right.


                public class User : Entity
                {
                    public User() { this.Posts = new List<Post>;}
                    public virtual string Name { get; set; }
                    public virtual IList<Post> Posts {get; set;}
                    public virtual IList<Favorite> Favorites { get; set;}
                }

                public class Post : Entity
                {
                    public Post() {}
                    public virtual string Title { get; set; }
                    public virtual User User { get; set; }
                }

                public class Favorite : Entity
                {
                    public virtual Post Post { get; set; }
                    public virtual User User { get; set; }
                    public virtual bool IsPublic {get; set;}
                    public virtual DateTime CreateDate {get; set;}
                }









On Thu, Dec 29, 2011 at 3:55 AM, Itzik Saban <[email protected]> wrote:

> Hi feelexit,
>
> To my opinion, you don't need a third entity called 'Favorite'. All you
> need is an association of many-to-many from User to Post that will be
> called 'Favorites' and will be a  IList<Post>.
>
> eventually, the User class will look like this:
>
>  public class User : Entity
>            {
>                public User() { this.Posts = new List<Post>;}
>                public virtual string Name { get; set; }
>                public virtual IList<Post> Posts {get; set;}
>                public virtual IList<Post> Favorites { get; set;}
>            }
>
> But don't forget to map the  Favorites  association as a many-to-many in
> your hbm/fluent configuration.
>
> 2011/12/28 feelexit <[email protected]>
>
>> I have 3 tables, they are very simple. User, Post, Favorite.
>>
>>            User Table:
>>            Id: int
>>            Name: string
>>            --------------------------------
>>
>>            Post Table:
>>            Id: int
>>            Title: string
>>            UserId: int  (this is the FK)
>>            --------------------------------
>>
>>            Favorite Table:
>>            UserId: int  (FK)
>>            PostId: int  (FK)
>>            --------------------------------
>>
>>
>> I create 2 class files for User and Post tables. Dont know how to add
>> Favorite table there, Favorite table allows User to bookmark their
>> favorite posts.
>>
>>
>>            public class User : Entity
>>            {
>>                public User() { this.Posts = new List<Post>;}
>>                public virtual string Name { get; set; }
>>                public virtual IList<Post> Posts {get; set;}
>>            }
>>
>>            public class Post : Entity
>>            {
>>                public Post() {}
>>                public virtual string Title { get; set; }
>>                public virtual User User { get; set; }
>>            }
>>
>>
>> some one suggests me to do this:
>>
>> public class Favorite : Entity
>> {
>>    public virtual Post Post { get; set; }
>>    public virtual User User { get; set; }
>> }
>>
>>
>>
>> I modify my files a little bit, still doesn't seem quiet right.
>>
>>
>>
>>            public class User : Entity
>>            {
>>                public User() { this.Posts = new List<Post>;}
>>                public virtual string Name { get; set; }
>>                public virtual IList<Post> Posts {get; set;}
>>                public virtual IList<Favorite> Favorites { get; set;}
>>            }
>>
>>            public class Post : Entity
>>            {
>>                public Post() {}
>>                public virtual string Title { get; set; }
>>                public virtual User User { get; set; }
>>                public virtual IList<Favorite> Favorites { get; set;}
>>            }
>>
>>            public class Favorite : Entity
>>            {
>>                public virtual Post Post { get; set; }
>>                public virtual User User { get; set; }
>>            }
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>>
>
> --
> Itzik Saban
>
> my blog <http://itziksaban.blogspot.com/>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to