开发者

Filtering a joined property in NHibernate

I have two tables that are considered a single entity in my domain model.

I join them in my IAutoMappingOverride by calling IgnoreProperty on the properties of the joined table and then using Join with a Map for each of the properties.

This configuration works, but I'm lost at attempting a filter on the columns of the joined table. If I call the following:

Session.CreateCriteria<PrimaryEntity>()
    .CreateCriteria("ExtraPropertiesTable", JoinType.InnerJoin)
    .Add(Expression.Eq("Language", language)) // Column on ExtraPropertiesTable
    .List(primaryEntitiesList);

I get the following exception:

QueryException: could not resolve property: ExtraPropertiesTa开发者_运维百科ble of: PrimaryEntity

I have also tried DetachedCriteria to no avail.

Any ideas?


If both tables are mapped to the same entity, you shouldn't have to do a join in the hibernate query, you should only refer to the entity, and hibernate will generate the join in the SQL query it generates. Also, the CreateCriteria method expect the name of a mapped entity, not a table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜