开发者

NHibernate Component mapping (Creating Criteria)

Is there any way to create an “alias” for a component?

I have a “Criteria Builder” that takes strings in the format of “Address.City” (or “User.Address.City”, …) and creates an ICriteria (filters and sorts) based on it.

I am using components to map the 开发者_如何学运维“Address” class so it stays in the same table as “User”.

The exception I am getting is:

NHibernate.QueryExceptioncould not resolve property: City of: MyNamespace.User

If I attempt to do not create an “alias” for the Address Component, it works just fine.

However, as it is a criteria builder, is there a way to detect that “Address” is a component and avoid the call criteria.CreateAlias(“Address”)? Any work around?

This is the same question as mine, however the solution is not viable to me (I do not create criteria manually for each query).

Any help would be much appreciated!


You can't create an Alias for Address because Address is not a mapped entity. The only difference between CreateAlias and CreateCriteria is that the former returns the original Criteria, whereas the latter returns the new Subcriteria. So the only classes you can create Criteria for are classes that have been mapped. Since components are not mapped classes, you can't create a criteria around them.

The only suggestion I have is to have your Address class either to implement an empty descriptor interface like IComponent or mark it with a custom ComponentAttribute. Then your CriteriaBuilder can check whether or not the class it's creating a criteria for has this meta data and ignore it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜