i am having a four models.. User,post,tag,comment.. the relationship i want to have with EF code first is
1) 1 user can have many posts, can create many tags, can have many comments
2) 1 post can have 1 user, many comments, and can have many tags
3) 1 tag can have 1 user, many post
4) 1 comment can have 1 user, 1 post
through google, i have come this far …but i am sure its not right …please help..
Updated Mapping
modelBuilder.Entity<User>().HasMany(p => p.Posts).WithRequired(u => u.Users);
modelBuilder.Entity<User>().HasMany(t => t.Tags).WithRequired(u => u.Users);
modelBuilder.Entity<User>().HasMany(c => c.Comments).WithRequired(u => u.Users);
modelBuilder.Entity<Post>().HasRequired(u => u.Users);
modelBuilder.Entity<Post>().HasMany(t => t.Tags).WithMany(p => p.Posts);
modelBuilder.Entity<Post>().HasMany(c => c.Comments);
modelBuilder.Entity<Comment>().HasRequired(u => u.Users);
modelBuilder.Entity<Comment>().HasRequired(p => p.Posts);
modelBuilder.Entity<Tag>().HasRequired(u => u.Users);
modelBuilder.Entity<Tag>().HasMany(p => p.Posts).WithMany(t => t.Tags);
please help.
If one User can have many Posts and Post can have single User your entities and mappings must be prepared for that.
If you define your entities correctly it should make correct mapping for you with default conventions. If you still to map it with fluent API you must use:
Which means one user can have many posts and post must have single user. That is 1-N mapping. For tag and post you need M-N mapping:
Which means one tag can have many posts and post can have many tags.
You will map other relations in the same way.