我正在使用一些多语言词典在应用程序的选择框中显示数据。 词典的架构如下:
其中的数据例如:
实体和映射如下:
public class HighestLevelOfEducation
{
public virtual int Id { get; set; }
public virtual DateTime CreatedAt { get; set; }
public virtual IDictionary<string, HighestLevelOfEducationLocalized> LocalizedData { get; set; }
}
public class HighestLevelOfEducation
{
public virtual string Name { get; set; }
}
public class HighestLevelOfEducationMap : ClassMapping<HighestLevelOfEducation>
{
public HighestLevelOfEducationMap()
{
this.Schema(SchemaConst.Dictionary);
this.PrimaryKeyId(x => x.Id);
this.Lazy(true);
this.Property(x => x.CreatedAt, mapping => mapping.NotNullable(true));
this.Map(
prop => prop.LocalizedData,
mapper =>
{
mapper.Schema(SchemaConst.Dictionary);
mapper.Fetch(CollectionFetchMode.Subselect);
mapper.Lazy(CollectionLazy.NoLazy);
mapper.Cascade(Cascade.DeleteOrphans | Cascade.All);
mapper.Table(nameof(HighestLevelOfEducationLocalized));
mapper.Key(keyMapper =>
{
keyMapper.Column("Id");
keyMapper.ForeignKey($"{typeof(HighestLevelOfEducation).Name}_{typeof(HighestLevelOfEducationLocalized).Name}_FK");
});
},
key =>
{
},
value =>
{
value.Component(x => x.Property(prop => prop.Name));
});
}
}
现在我面临一项新任务-使用like语句按他的名字查找字典。
例如我想找到一个在任何文化中名称都包含“ Sience”的级别:
var levels = session.Query<HighestLevelOfEducation>()
.Where(x => x.LocalizedData.Any(l => l.Value.Name.Contains("Science")))
.ToList();
我已经尝试了一些类似我的答案的示例,这些示例使用的是Dictionary,但是我找不到有关将字典用于复杂对象的任何答案。你能帮我完成这个任务吗?
P.S。 nHibernate的版本是4.1.1.400