开发者

nhibernate - display order - pattern/solution?

I have a collection of ReportColumns in开发者_JAVA技巧 a Report object.

The ReportColumns has a DisplayOrder field which sets where abouts in the report the column is displayed. these columns are re-orderable in the designer ui and i can write some hacky code to change the order of them - but was wondering if there's anyway in nhib to take care of re-ordering entities based on a column? or perhaps a standard pattern to follow? seems like a fairly standard thing to want to do.

w://


ended up using a trigger:

IF EXISTS (SELECT name FROM sysobjects
      WHERE name = 'colmodels_insupd' AND type = 'TR')
   DROP TRIGGER employee_insupd
GO
CREATE TRIGGER colmodels_insupd
ON ColModels
FOR INSERT, UPDATE
AS

update cm
set displayorder = a.rownumber
from
colmodels cm
inner join
(
select colmodels.id, row_number() OVER(partition by colmodels.reportid ORDER BY colmodels.displayorder, colmodels.id desc) as rownumber
from colmodels inner join inserted 
on colmodels.reportid = inserted.reportid and  colmodels.deleted = 0 and colmodels.hidden = 0 
) a
on cm.id = a.id


I don't know if I understand the question correctly but : You can ask to NH to retrieve the colums in the order specified by a column (even if it's not mapped) :

HasMany(x => x.Columns)
                .Inverse()
                .Cascade.All()
                .Not.LazyLoad()
                .OrderBy("DisplayOrder")

Here the ReportColumn objects in the Columns property will in the order specified by the OrderBy.

In HBM it will be the order-by attribute of your collection :

http://nhibernate.info/doc/nh/en/index.html#collections-mapping

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜