Do you have tried a <component> in a <join>.

2009/8/4 Dmitiry Nagirnyak <[email protected]>

> Could anyone please suggest?
>
> Am I doing it the right way?
>
>
> 2009/8/4 Dmitiry Nagirnyak <[email protected]>
>
>> Only one thing I can do NOW to pass the test is modify the Product class:
>> 1) Make Image setter non-public.
>> 2) Change image via method. That will:
>> 3) Retrieve the Session (via ServiceLocator).
>> 4) Delete old Image.
>> 5) Assign the new Image.
>>
>> Is it the only way of oding it?
>> Is it really impossible to do handle this via mapping?
>>
>>
>> Cheers,
>> Dmitriy.
>> 2009/8/4 Dmitiry Nagirnyak <[email protected]>
>>
>>  Yes, BinaryContent can be used in other relations too.
>>>
>>> I don't mind to change the mapping to one-to-one, but it doesn't look
>>> like it solves this problem.
>>> I see what you mean about the cascade.
>>>
>>> When I was using other O/R-M I just set the relation type to Composition
>>> (not just Aggreagation) and it was working great.
>>> I am not sure how I can achive the same with NH.
>>>
>>> Should I use some hack or similar to make my test pass?
>>>
>>> Cheers,
>>> Dmitriy.
>>>
>>> 2009/8/4 Fabio Maulo <[email protected]>
>>>
>>> Try to think about this... What mean "cascade" ?
>>>>
>>>> Cascade mean that the action applied to the relation owner is applied to
>>>> the other side of the relation.
>>>> So:
>>>> - if you save a Product NH will save the Image
>>>> - if you delete a Product NH will delete the Image
>>>> and so on.
>>>>
>>>> The issue NH-1262 perhaps can be implemented because the one-to-one is
>>>> a bidirectional relation but your case is completely different.
>>>> Your relation is Product-to-BinaryContent and BinaryContent has a
>>>> different autonomy lify-cycle.
>>>>
>>>> Is the class BinaryContent used in some other relation with other
>>>> classes ?
>>>>
>>>> 2009/8/3 Dmitiry Nagirnyak <[email protected]>
>>>>
>>>>> Anybody please?
>>>>>
>>>>> 2009/8/3 Dmitiry Nagirnyak <[email protected]>
>>>>>
>>>>> Noo! Tell me that's impossible!
>>>>>>
>>>>>> http://nhjira.koah.net/browse/NH-1262
>>>>>> :((
>>>>>>
>>>>>> On 03/08/2009, Dmitiry Nagirnyak <[email protected]> wrote:
>>>>>> > It is not applicable to many-to-one. So it just doesn't work.
>>>>>> > It would be nice if I could do this.
>>>>>> >
>>>>>> > 2009/8/3 Tuna Toksoz <[email protected]>
>>>>>> >
>>>>>> >> all-delete-orhpans
>>>>>> >>
>>>>>> >> Tuna Toksöz
>>>>>> >> Eternal sunshine of the open source mind.
>>>>>> >>
>>>>>> >> http://devlicio.us/blogs/tuna_toksoz
>>>>>> >> http://tunatoksoz.com
>>>>>> >> http://twitter.com/tehlike
>>>>>> >>
>>>>>> >>
>>>>>> >>
>>>>>> >>
>>>>>> >>
>>>>>> >> On Mon, Aug 3, 2009 at 9:38 AM, Dmitiry Nagirnyak
>>>>>> >> <[email protected]>wrote:
>>>>>> >>
>>>>>> >>> Hi,
>>>>>> >>>
>>>>>> >>> I have difficulty making the test below to pass. I need to tell NH
>>>>>> that
>>>>>> >>> there's only 1 Image related to Product and if another is assigned
>>>>>> the
>>>>>> >>> old
>>>>>> >>> one should be deleted.
>>>>>> >>>
>>>>>> >>> Some help please?
>>>>>> >>>
>>>>>> >>> // THE TEST
>>>>>> >>> [Test]
>>>>>> >>> public void ReplaceProductImage_DeletesOldRecord() {
>>>>>> >>>  // Initialise
>>>>>> >>>  var p = new Product {
>>>>>> >>>   Image = new BinaryContent {
>>>>>> >>>    Content = Encoding.ASCII.GetBytes("image")
>>>>>> >>>   }
>>>>>> >>>  };
>>>>>> >>>  Session.Save(p);
>>>>>> >>>  Session.Flush();
>>>>>> >>>  // Exercise
>>>>>> >>>  var totalImagesBefore = Session.Linq<BinaryContent>().Count();
>>>>>> >>>  p.Image = new BinaryContent {
>>>>>> >>>   Content = Encoding.ASCII.GetBytes("another")
>>>>>> >>>  };
>>>>>> >>>  Session.Flush();
>>>>>> >>>  var totalImagesAfter = Session.Linq<BinaryContent>().Count();
>>>>>> >>>  // Verify
>>>>>> >>>  totalImagesAfter.Should().Be.EqualTo(totalImagesBefore);
>>>>>> >>> }
>>>>>> >>>
>>>>>> >>>
>>>>>> >>> // THE MODEL
>>>>>> >>> public class Product {
>>>>>> >>>  public virtual int Id { get; protected set; }
>>>>>> >>>  public virtual BinaryContent Image { get; set; }
>>>>>> >>> }
>>>>>> >>> public class BinaryContent {
>>>>>> >>>  public virtual int Id { get; protected set; }
>>>>>> >>>  public virtual byte[] Content { get; set; }
>>>>>> >>> }
>>>>>> >>> // THE MAPPING
>>>>>> >>> public class BinaryContentMap : ClassMap<BinaryContent> {
>>>>>> >>>  public BinaryContentMap() {
>>>>>> >>>   Id(x => x.Id).GeneratedBy.Native();
>>>>>> >>>   Map(x =>
>>>>>> x.Content).CustomTypeIs("BinaryBlob").WithLengthOf(102400);
>>>>>> >>>  }
>>>>>> >>> }
>>>>>> >>>
>>>>>> >>>
>>>>>> >>>
>>>>>> >>> Cheers,
>>>>>> >>> Dmitriy.
>>>>>> >>>
>>>>>> >>>
>>>>>> >>>
>>>>>> >>
>>>>>> >> >>
>>>>>> >>
>>>>>> >
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Fabio Maulo
>>>>
>>>>
>>>>
>>
>
>
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to