just grabbed this from the codecampserver trunk ...

Add Sponsor

        public virtual void AddSponsor(Sponsor sponsor)
        {
            _sponsors.Add(sponsor);
        }

Remove Sponsor

        public virtual void RemoveSponsor(Sponsor sponsor)
        {
            _sponsors.Remove(sponsor);
        }

Unit Test

                [Test]
                public void ShouldDeleteSponsor()
                {
                        Conference conf = CreateConference("", "");
                        IConferenceRepository repository = new
ConferenceRepository(_sessionBuilder);
                        Sponsor sponsorToDelete = CreateSponsor("test");
                        Sponsor sponsorToKeep = CreateSponsor("test2");
                        conf.AddSponsor(sponsorToDelete);
                        conf.AddSponsor(sponsorToKeep);
                        repository.Save(conf);
                        getSession().Dispose();

                        using (ISession session = getSession())
                        {
                                var confFromDb = 
session.Get<Conference>(conf.Id);
                                confFromDb.RemoveSponsor(sponsorToDelete);
                                repository.Save(confFromDb);
                        }

                        using (ISession session = getSession())
                        {
                                var confFromDb = 
session.Get<Conference>(conf.Id);
                                var sponsors = new 
List<Sponsor>(confFromDb.GetSponsors());
                                Assert.That(sponsors.Contains(sponsorToKeep), 
Is.True);
                                Assert.That(sponsors.Contains(sponsorToDelete), 
Is.False);
                        }
                }

Shows you can do what I'm describing with NHibernate. Not sure why it
isn't working with AR.

On Oct 28, 7:48 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Just as some background, I do have ICartRepo and CartRepo (I've been
> oversimplifying everything). The model classes handles the logic
> (calculating prices, update quantity, delete item, emptycart, etc.)
> and the repo saves things when I'm done.
>
> This is where it gets really confusing for me. IMHO the cart should
> know what items it has and how to get rid of them (or change their
> quantity, or add a new item). Then saving the cart (and its contents)
> should be handled by the repository. When I want the cart back, get it
> from the repository. The real work happens in the model, not the repo.
>
> I don't understand why we want to have the repository managing what it
> is in the cart. Doesn't this go against what we've been trying to
> accomplish (a model that lives outside its persistence)?
>
> On Oct 28, 7:01 pm, "Victor Kornov" <[EMAIL PROTECTED]> wrote:
>
> > btw, is there a reason for that other than AR/NH being incapable (or we) to
> > do that simpler way (i.e. just detaching it from relevan aggregate root)?
>
> > On Wed, Oct 29, 2008 at 1:07 AM, Ken Egozi <[EMAIL PROTECTED]> wrote:
> > > create ICartRepository in the domain layer and ARCartRepository in the
> > >> persistance layer,
>
> > > I second that.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to