Hi,
I'm hoping somebody can help me with this, I'm trying to write the mapping classes for a class that is subclassed into a generic class. Its easier to descibe with code, so here is my model...
public abstract class TagBase
{
public virtual int Id { get; private set; }
public virtual TagTypeEnum TagType { get; set; }
public virtual string Value { get; set; }
public virtual bool IsSystemTag { get; private set; }
public virtual bool isDeleted { get; set; }
public TagBase()
{
}
public TagBase(TagTypeEnum tagType)
{
this.TagType = tagType;
}
public override string ToString()
{
return Value;
}
}
public class Tag<TLinkedItem> : TagBase where TLinkedItem : ITagged<TLinkedItem>
{
public virtual List<TLinkedItem> LinkedItems { get; set; }
}
As you can see Tag
is generic but is constrained to only those classes that implement ITagged<T>
The idea is that an entity has Tags and in turn a tag has a list of LinkedItems that are strongly typed.
Tags cannot be shared amongst different types of entity
I only have two entities in my model that support tagging so far thay are Display
and Asset
I've tried to map this with the following Fluent NHibernate code;
public class TagBaseMap : ClassMap<TagBase>
{
public TagBaseMap()
{
Table("Tag");
Id(tag => tag.Id);
Map(tag => tag.Value).Not.Nullable().Length(50);
Map(tag => tag.IsSystemTag).Not.Nullable();
Map(tag => tag.isDeleted).Not.Nullable();
Map(tag => tag.TagType).CustomType<Int32>().Not.Nullable();
}
}
public class DisplayTagMap : SubclassMap<Tag<Display>>
{
public DisplayTagMap()
{
HasManyToMany(displayTag => displayTag.LinkedItems).Inverse().Table("DisplayTagLink");
}
}
public class AssetTagMap : SubclassMap<Tag<Asset>>
{
public AssetTagMap()
{
HasManyToMany(assetTag => assetTag.LinkedItems).Inverse().Table("AssetTagLink");
}
}
When I try and build the database, I'm targetting Sql Server, from this mapping I'm getting this error "Incorrect syntax near '`'."
Am I right in thinking caused by .Net's naming of generic classes ie,
'{[Model.Tag'1[[Model.Asset, Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].LinkedItems, NHibernate.Mapping.Bag(Model.Tag'1[[Model.Asset, Saturn.ConnectVision.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].LinkedItems)]}'
Am I doing something daft here?
Is there a way around this problem?
Thanks in advance for any advice.