also, tried changing to:

ActiveRecordMediator<T>.SaveAndFlush(entity);

and still the same result.


On Wed, Oct 29, 2008 at 4:38 PM, Kyle West <[EMAIL PROTECTED]> wrote:

> EcoRepo looks like this ...
>
>         public void SaveCart(EcoShoppingCart cart)
>         {
>             shoppingCartRepository.Save(cart);
>         }
>
> shoppingCartRepo is an IRepo<EcoShoppingCart>
>
> Repo<ShoppingCart> looks like this:
>
>         public T Save(T entity)
>         {
>             // Success = false by default
>             entity.Success = false;
>
>             // Crazy Resharper converted if statement
>             // If record.Id = 0 Insert, else, Update
>             entity.SuccessMsg = entity.Id == 0 ? entity.InsertSuccessMsg :
> entity.UpdateSuccessMsg;
>
>             // Always update DateModified
>             entity.DateModified = DateTime.Now;
>
>             if (entity.IsValid())
>             {
>                 ActiveRecordMediator<T>.Save(entity);
>                 entity.Success = true;
>             }
>
>             return entity;
>
>         }
>
>
> On Wed, Oct 29, 2008 at 4:28 PM, Jimmy Shimizu <[EMAIL PROTECTED]>wrote:
>
>>
>> How do you update your Cart in your repository? Are you explicitly
>> calling CreateAndFlush() or SaveAndFlush()?
>>
>> Where do you flush? How does your SaveCart() look like in your
>> implementation of IEcoRepository?
>>
>> On 29 okt 2008, at 14.26, [EMAIL PROTECTED] wrote:
>>
>> >
>> > Actually .. I didn't fix it. I should have run all the tests before
>> > posting.
>> >
>> > When doing Inverse=true the relationship is never created in the first
>> > place ... so all the add-to-cart tests failed.
>> >
>> > On Oct 29, 9:12 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> >> I fixed it! I just had to set Inverse=true.
>> >>
>> >> [HasMany(typeof(EcoShoppingCartItem), ColumnKey = "ShoppingCartId",
>> >> Table = "EcoShoppingCartItems", Lazy = true, Inverse=true, Cascade =
>> >> ManyRelationCascadeEnum.All)]
>> >>
>> >> I'm not exactly what inverse=true means but got the idea from this
>> >> linkhttp://www.hibernate.org/359.html(bottom<http://www.hibernate.org/359.html%28bottom>of
>> >>  page) and it works.
>> >>
>> >> Now, it doesn't actually delete the shoppingcartitem from the
>> >> database, but it does disconnect it from the cart (sets
>> >> shoppingcartid
>> >> = null). Not ideal in this situation but I can see why we wouldn't
>> >> want every thing removed from a collection to be deleted from the
>> >> database so I'm happy with it.
>> >>
>> >> Now I've gotta figure out what inverse=true means.
>> >>
>> >> On Oct 29, 9:00 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> >>
>> >>> Here is the integration test I am using ...
>> >>
>> >>>         [Test]
>> >>>         public void CanDeleteItemsFromShoppingCartAndSave()
>> >>>         {
>> >>>             EcoShoppingCart cart;
>> >>>             EcoShoppingCart cartFromDB;
>> >>>             string uniqueId = Guid.NewGuid().ToString();
>> >>>             var ecoRepository =
>> >>> ObjectFactory.GetInstance<IEcoRepository>();
>> >>
>> >>>             var catalogRepository =
>> >>> ObjectFactory.GetInstance<ICatalogRepository>();
>> >>>             ItmItem item = catalogRepository.GetItem(48046);
>> >>
>> >>>             using (new SessionScope())
>> >>>             {
>> >>>                 cart = ecoRepository.GetCart(uniqueId);
>> >>
>> >>>                 cart.AddItem(item);
>> >>>                 cart.AddItem(item);
>> >>
>> >>>                 ecoRepository.SaveCart(cart);
>> >>>             }
>> >>>             using (new SessionScope())
>> >>>             {
>> >>>                 cart = ecoRepository.GetCart(uniqueId);
>> >>
>> >>>                 cart.DeleteItem(item);
>> >>
>> >>>                 ecoRepository.SaveCart(cart);
>> >>>             }
>> >>
>> >>>             using (new SessionScope())
>> >>>             {
>> >>>                 cartFromDB = ecoRepository.GetCart(uniqueId);
>> >>>                 Assert.AreNotSame(cart, cartFromDB);
>> >>>                 Assert.AreEqual(cart.Items.Count, 0);
>> >>>             }
>> >>>         }
>> >>
>> >>> And here is the unit test:
>> >>
>> >>>         [Test]
>> >>>         public void CanDeleteItem()
>> >>>         {
>> >>>             var cart = new
>> >>> EcoShoppingCart(FakeEntityFactory.subscription, "12345");
>> >>>             cart.AddItem(FakeEntityFactory.item);
>> >>>             cart.AddItem(FakeEntityFactory.item);
>> >>
>> >>>             cart.DeleteItem(FakeEntityFactory.item);
>> >>
>> >>>             Assert.AreEqual(cart.Items.Count, 0);
>> >>>         }
>> >>
>> >>> Thanks so much for sticking thru this with me!
>> >>
>> >>> On Oct 29, 2:10 am, "Markus Zywitza" <[EMAIL PROTECTED]>
>> >>> wrote:
>> >>
>> >>>> Do you use SessionScope? Did you flush the scope or used another
>> >>>> to check
>> >>>> the results?
>> >>
>> >>>> What happens if you refresh the Cart? Does the deleted item show
>> >>>> up again or
>> >>>> is it "just" not deleted from the database but not connected to
>> >>>> the cart
>> >>>> anymore?
>> >>
>> >>>> -Markus
>> >>>> 2008/10/29 [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>> >>
>> >>>>> 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