I have structure similar to this:
public class Entity
{
public int Id { get; set; }
public IDictionary<string, EntityLocale> Locales { get; set; }
}
public class EntityLocale
{
public string Name { get; set; }
}
public class EntityMap : ClassMap<Entity>
{
public EntityMap()
{
HasMany(x => x.Locales)
.AsMap<string>("Locale")
.Component(
c => {
c.Map(x => x.Name);
}
);
}
}
And I want to recieve all names of product locales with a "en" key. With linq it will be:
var names = Session.QueryOver<Product>().List().Select(x => x.Locales["en"].Name).ToList();
How do I achieve this with nhibernate? (I don't care if it's QueryOver or Criteria api, I just don't want to select everything).
Update
I came up with the following ugly hack (which I'm not satisfied with, I don't want any sql in my code):
var names = Session.CreateSQLQuery("SELECT Name FROM ProductLocales WHERE Locale = 'en'").List<string>()