I'd like to use your second solution. So I've added a surrogate key to "tblTagEntity" (TagEntityId) and created the class
class TagEntity TagEntityId - int Tag - Tag In the mapping I've created a many-to-one for Tag. However then I'm lost again. I'm thinking I need to do a many-to-any for EntityId and EntityType in the TagEntity map? Otherwise I still don't understand how to map EntityType. On Mar 29, 7:18 pm, José F. Romaniello <[email protected]> wrote: > Sorry, I've checked your domain and tables again and what you need is > many-to-*M*any. > > From here you have two options: > 1-A real many-to-may. A many to many mappings need an intermediate table per > case. So, you need two extra tables one for BlogsTags and one for ImageTags. > > http://nhforge.org/doc/nh/en/index.html#collections-ofvalues > > for this option you don't need to map the "TagEntity" table. > > 2-Map TagEntity as an entity, map Blog.TagEntities and map TagEntity.Tag > (many to one). You can have a property that expose the tag collection as > follows: > > public IEnumerable<Tag> Tags{ > get{ return TagEntities.Select(te => te.Tag); > > } > > I think that if you use this approach maybe you can maintain the schema, but > I need to think more about it. > > 2010/3/29 ZNS <[email protected]> > > > > > So you mean I create a new entity called TagEntity and add your > > mapping to for example ImageMap? In that case every image has one > > TagEntity and no tags? > > I'm new to NHibernate so I'm sorry if I'm a little slow ;) > > > On Mar 29, 5:29 pm, José F. Romaniello <[email protected]> wrote: > > > <any name='TagEntity' meta-type='System.String' id-type='System.Int32'> > > > <meta-value class='MyNamespace.Image, MyNamespace' value='IMG'/> > > > <meta-value class='MyNamespace.Blog, MyNamespace' value='BLOG'/> > > > <column name='EntityType'/> > > > <column name='EntityId'/> > > > </any> > > > > I think the default value is the full qualified name of the class.... But > > I > > > don't remember. > > > > 2010/3/29 ZNS <[email protected]> > > > > > Thank you for replying. However I've been looking at any and many-to- > > > > any already but I can't quite get the hang of how to implement it in > > > > my scenario. You wouldn't care to ellaborate? > > > > > On Mar 29, 4:15 pm, José F. Romaniello <[email protected]> wrote: > > > > > Yes, have a look to <any> and <many-to-any> mappings tags. > > > > > > 2010/3/29 ZNS <[email protected]> > > > > > > > Hi! > > > > > > > I've been wrecking my mind on how to get my tagging of entities to > > > > > > work. I'll get right into some database structuring: > > > > > > > tblTag > > > > > > TagId - int32 - PK > > > > > > Name > > > > > > > tblTagEntity > > > > > > TagId - PK > > > > > > EntityId - PK > > > > > > EntityType - string - PK > > > > > > > tblImage > > > > > > ImageId - int32 - PK > > > > > > > tblBlog > > > > > > BlogId - int32 - PK > > > > > > > ----------------------------- > > > > > > > class Image > > > > > > Id > > > > > > EntityType { get { return "MyNamespace.Entities.Image"; } > > > > > > IList<Tag> Tags; > > > > > > > class Blog > > > > > > Id > > > > > > EntityType { get { return "MyNamespace.Entities.Blog"; } > > > > > > IList<Tag> Tags; > > > > > > > ------------------------------- > > > > > > > The obvious problem I have here is that EntityType is an identifer > > but > > > > > > doesn't exist in the database. If anyone could help with the this > > > > > > mapping I'd be very grateful. > > > > > > > -- > > > > > > 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]<nhusers%[email protected]> > > <nhusers%[email protected]<nhusers%[email protected]> > > > > > <nhusers%[email protected]<nhusers%[email protected]> > > <nhusers%[email protected]<nhusers%[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]<nhusers%[email protected]> > > <nhusers%[email protected]<nhusers%[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]<nhusers%[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.
