tag:blogger.com,1999:blog-32609450.post36606410204567279..comments2023-09-15T13:14:58.827+01:00Comments on Colin Jack's Blog: NHibernate - Mapping Custom CollectionsColin Jackhttp://www.blogger.com/profile/01403166737046938219noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-32609450.post-60541697665009727562009-11-10T10:14:01.637+00:002009-11-10T10:14:01.637+00:00Since I use my blog to help me remember things...
...Since I use my blog to help me remember things...<br /><br />Also worth noting is that you want to enforce the rules on collections upfront. <br /><br />If you don't then the contents of the collection can be invalid and when validating the owning aggregate you have to validate the entire collection which is inefficient and over-complicated.Colin Jackhttps://www.blogger.com/profile/01403166737046938219noreply@blogger.comtag:blogger.com,1999:blog-32609450.post-53497542637359240622008-11-26T00:17:00.000+00:002008-11-26T00:17:00.000+00:00Excellent post as always, but it leaves me a littl...Excellent post as always, but it leaves me a little confused about the role of custom collections vs repositories. Repositories emulate a custom collection, thereby abstracting persistence concerns. Assuming Order is an aggregate root, are you saying you might have an OrderRepository <B>and</B> an OrderCollection?Julian Maughanhttps://www.blogger.com/profile/07794070415365246965noreply@blogger.comtag:blogger.com,1999:blog-32609450.post-16034811970813880922008-10-22T21:47:00.000+01:002008-10-22T21:47:00.000+01:00Cool, definitely be interested to see what you thi...Cool, definitely be interested to see what you think of the result.Colin Jackhttps://www.blogger.com/profile/01403166737046938219noreply@blogger.comtag:blogger.com,1999:blog-32609450.post-56974317841438702022008-10-22T21:46:00.000+01:002008-10-22T21:46:00.000+01:00Perfect sense now!I thought you had them all inher...Perfect sense now!<BR/><BR/>I thought you had them all inheriting off each other for a moment - and thats just crazy talk.<BR/><BR/>Going to impliment it now.<BR/><BR/>Will let you know.<BR/><BR/>DaveAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-32609450.post-44324225557152028882008-10-22T21:42:00.000+01:002008-10-22T21:42:00.000+01:00@DaveSorry yeah, basically your FooCollection inhe...@Dave<BR/>Sorry yeah, basically your FooCollection inherits either directly from IReadonlyCollection or from ReadOnlyCollection (a base class that takes care of 90+% of the nonsense needed to implement IEnumerable and so on). <BR/><BR/>Means I can expose the FooCollection directly, or expose IEnumerable or expose IReadonlyCollection.<BR/><BR/>In FooCollection you add any custom behavior e.g. disallowing adding Foos if there is another Foo of that type already in the collection.<BR/><BR/>Does that make sense?Colin Jackhttps://www.blogger.com/profile/01403166737046938219noreply@blogger.comtag:blogger.com,1999:blog-32609450.post-25808585102484221892008-10-22T21:33:00.000+01:002008-10-22T21:33:00.000+01:00Colin, this article is exactly what I was looking ...Colin, this article is exactly what I was looking for.<BR/><BR/>However i am finding it a tad hard to follow from your examples.<BR/><BR/>In particular:<BR/>" public interface IReadOnlyCollection< TItem > : IReadOnlyCollection, ..."<BR/><BR/>I do not see how this applies to the Custom collection implimenting<BR/><BR/>ReadOnlyCollection<BR/><BR/>Its late and i may just be being stupid.<BR/><BR/>Dave The NinjaAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-32609450.post-1555250232950281702008-10-10T19:03:00.000+01:002008-10-10T19:03:00.000+01:00@TobinHey. The specifications in the approach I'm ...@Tobin<BR/>Hey. <BR/><BR/>The specifications in the approach I'm describing were just for in-memory as this was pre-Linq but when I next try it I'm going to try Linq specifications and then you could use them in memory and/or could use them in the repositories. <BR/><BR/>Only problem I have with that approach right now is that Linq to NHib isn't fully enough implemented to support some of the things I need.Colin Jackhttps://www.blogger.com/profile/01403166737046938219noreply@blogger.comtag:blogger.com,1999:blog-32609450.post-84051154053884392612008-10-05T23:34:00.000+01:002008-10-05T23:34:00.000+01:00I was thinking about doing something like this, fo...I was thinking about doing something like this, for similar reasons.<BR/><BR/>I'b interesting in seeing how your Specification works. Can you show more code for this? Do you hit the database, or is it for in-memory filtering, or both?Tobin Harrishttps://www.blogger.com/profile/02203581553681366247noreply@blogger.comtag:blogger.com,1999:blog-32609450.post-60144311274117759002008-09-05T08:50:00.000+01:002008-09-05T08:50:00.000+01:00@DanGood point, I'd forgotten about that aspect.@Dan<BR/>Good point, I'd forgotten about that aspect.Colin Jackhttps://www.blogger.com/profile/01403166737046938219noreply@blogger.comtag:blogger.com,1999:blog-32609450.post-61192886113603552582008-09-04T22:50:00.000+01:002008-09-04T22:50:00.000+01:00We came up with a solution like this and it is a u...We came up with a solution like this and it is a useful shortcut, if you don't want to go with a full blown custom NH collection implementation.<BR/><BR/>One niggle is that you need to include the name of the inner list field in the property path within your Criteria queries, e.g. .AddCriteria("OrderLines._innerList.Product.Id"... Naming the inner list something like "Items" minimises the mess.Anonymousnoreply@blogger.com