I have a "bookmark" entity that has tags which are strings. In C#, the bookmark Poco is similar to:
public class BookmarkEntity
{
public virtual Guid Id { get; set; }
public virtual ISet<string> Tags { get; set; }
}
I've automapped the entity with this override:
public class BookmarkEntityMappingOverride : IAutoMappingOverride<BookmarkEntity>
{
public void Override(AutoMapping<BookmarkEntity> mapping)
{
mapping.HasManyToMany(x => x.Tags).AsSet().Element("Value").Not.LazyLoad();
}
}
This generates these two tables:
create table "BookmarkEntity" (
Id UNIQUEIDENTIFIER not null,
primary key (Id)
)
create table Tags (
BookmarkEntity_id UNIQUEIDENTIFIER not null,
Value TEXT,
constraint FK9061CD2928F7F2F9 foreign key (BookmarkEntity_id)
references "BookmarkEntity"
)
Now, I'd like to be able to get the unique set of tags from the SQLite-backed database. Currently I'm executing this query:
SELECT DISTINCT Value FROM Tags ORDER BY Value
This does what I want, but I'd like to use the Criteria API to get it a little more strongly typed. I started with this effort:
Session.CreateCriteria<BookmarkEntity>()
.SetProjection(
Projections.Distinct(Projections.Property<BookmarkEntity>(b => b.Tags)))
.AddOrder(Order.Asc(Projections.Property("Value")))
.List<string>();
But this doesn't work because it's trying to query over the Bookmarks table. What do I need to do to get this to be similar to my hardcoded SQL query?