You DO NOT want to have a PostTag entity to worry about. NHibernate can handle
this as a many-to-many association.
If you were to add a Posts collection to Tag I'm guessing that auto-mapping
would make it all just work. However, you probably don't want that. You want
something like this:
public class PostMappingOverride : IAutoMappingOverride<Post>
{
public void Override(AutoMapping<Post> mapping)
{
mapping.HasManyToMany(x => x.Tags)
.Access.CamelCaseField()
.ChildKeyColumn("TagId")
.ParentKeyColumn("PostId")
.Cascade.None()
.Table("PostTag");
}
Tim
On Tuesday, September 27, 2011 at 6:15 PM, Dando wrote:
> Hi,
>
> I'm new to FNH, and I'm currently developing a project with Sharp
> architecture. I'm new to ORMs, being used to a more direct hand in
> sql.
>
> Here were my original classes:
>
> class Post : Entity
> {
> string name
> string content
> List<Tag>
> }
>
> class Tag : Entity
> {
> string name
> }
>
> I let Automapper do it's stuff, but it was creating a foreign key in
> the Tag table back to Post, which I didn't want, as I wanted Tag to be
> it's own entity. I was expecting a join table of PostId, TagID to be
> created (inferred) upon schema generation.
>
> So, after some reading, I added the join table to my classes section:
>
> class PostTag : Entity
> {
> Post post
> Tag tag
> }
>
>
> and I changed the Post table to the following:
>
> class Post : ENtity
> {
> string name
> IList <PostTag>
> }
>
> Tag class stays the same. Now the generated schema creates the join
> table schema as well. Schemas now look as follows:
>
> Post{id, name, content}
>
> Tag{id, name}
>
> PostTag{id, PostFK}
>
>
>
> For PostTag, the TagFK isn't there.
>
> Is there a way of doing this with automapper? Also, I don't think
> there should be a normal Id column in this table. It should
> presumably be a table with a composite PK of PostId and TagID?
>
> I don't want to be putting IList <PostTag> onto my Tag class, as the
> Tag class should not have a reference going back to the Post object.
>
> Would anybody be able to help here? Does this need an override, and
> if so, how do I go about this?
>
> I'm sorry if this is an EXTREMELY noobish question!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To post to this group, send email to [email protected]
> (mailto:[email protected]).
> To unsubscribe from this group, send email to
> [email protected]
> (mailto:[email protected]).
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" 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/fluent-nhibernate?hl=en.