我试图用索引列映射列表。这工作正常,但我也想能够从HQL查询索引列。当我这样做,HQL抛出异常:将属性映射到索引列
NHibernate.QueryException:无法解析属性:人的职位:成分[地点,时间]
为了能够从查询WayPoint.Position列HQL,我在WayPoint-class中创建了一个Position-property,我想将这个属性映射到Position-column。
我曾尝试用:
wp.Map(x => x.Position).Column("Position");
但这导致MappingException:
NHibernate.MappingException:重复列映射集合:Route.WayPoints柱:位置
public class RouteMap : ClassMap<Route>
{
private const string LocationKey = "LocationIndex";
public RouteMap()
{
Not.LazyLoad();
ReadOnly();
Id(x => x.Id).GeneratedBy.Assigned();
Version(x => x.Version);
Map(x => x.Time);
References(x => x.StartingPoint).UniqueKey(LocationKey);
References(x => x.Destination).UniqueKey(LocationKey);
HasMany(x => x.WayPoints).Component(wp =>
{
wp.Map(x => x.Time);
//wp.Map(x => x.Position).Column("Position");
wp.Component(wp2 => wp2.Location, gl =>
{
gl.Map(x => x.Latitude);
gl.Map(x => x.Longitude);
}
);
}
).AsList(index => index.Column("Position")).Cascade.All();
}
}
create table `Route` (
Id VARCHAR(40) not null,
Version INTEGER not null,
Time BIGINT,
StartingPoint_id VARCHAR(40),
Destination_id VARCHAR(40),
primary key (Id),
unique (StartingPoint_id, Destination_id)
)
create table WayPoints (
Route_id VARCHAR(40) not null,
Latitude DOUBLE,
Longitude DOUBLE,
Time BIGINT,
Position INTEGER not null,
primary key (Route_id, Position)
)
是否可以映射Position属性?还是有另一种方法让HQL知道位置索引字段?
谢谢,正是我一直在寻找。 – 2010-08-30 09:44:36