Hi Richard,

Now I think I found the problem. I have a function IncrementAmount
(decimal value). This function was protected internal and changing it
to public it will work, even if the property Amount is private set.

So I think that the problem has relation to the Internal restriction.
I don't know why since the function is marked as protected internal
and not only as internal. To give you a clear look I'll write a
similar code here:

public class Foo
{
    public virtual decimal Amount { get; private set; }

    protected internal void IncrementAmount(decimal value)
    {
        this.Amount += value;
    }
}

public class Bar
{
    public Foo Foo = new Foo();
}

Bar mapping:
<many-to-one name="Foo" column="Foo_Id" class="Foo"  not-null="true" /
>

var bar = s.Get<Bar>(10);
bar.Foo.IncrementAmount(1);

TESTS RESULTS FOR THE ABOVE CODE:

Modifying the property:

protected internal void IncrementAmount(decimal value);

public virtual decimal Amount { get; private set; } // NOT OK
public virtual decimal Amount { get; protected set; }  // NOT OK
public virtual decimal Amount { get; set; }  // OK


Modifying the function:

public void IncrementAmount(decimal value);

public virtual decimal Amount { get; private set; } // OK
public virtual decimal Amount { get; protected set; }  // OK
public virtual decimal Amount { get; set; }  // OK

Modifying the mapping:

<many-to-one name="Foo" column="Foo_Id" class="Foo"  not-null="true"
fetch="join" /> // ALWAYS OK - Even with internal

So yes, I think this behavior has relation with the internal
restriction. What do you think?

Thanks

On 28 jan, 06:48, "Richard Brown \(gmail\)" <[email protected]>
wrote:
> I think we need to see the code that modifies the Amount property.
>
> If the property is protected, it has to be inside a method of the class (or
> one of its subclasses).
>
> --------------------------------------------------
> From: "CassioT" <[email protected]>
> Sent: Thursday, January 28, 2010 5:04 AM
> To: "nhusers" <[email protected]>
> Subject: [nhusers] Re: Proxy and property modification
>
>
>
> > Hi Richard,
>
> > Like I said, take:
>
> > public virtual decimal Amount { get; protected set; }
>
> > Anything that I try to put in Amount is denied. If Amount == 0 and I
> > try something like Amount = 5, Amount will not be modified.
>
> > But like I said before, without the protected restriction or using
> > fetch="join" (many-to-one association) it works
>
> > I tested the same code with pure classes (No NHibernate interaction),
> > just to see if it was a .NET problem, and of course, it worked.
>
> > Thanks
>
> > On Jan 27, 8:19 pm, "Richard Brown \(gmail\)"
> > <[email protected]> wrote:
> >> Hi,
>
> >> Can you show the code that modifies the object?  (accesses the mutator)
>
> >> Thanks,
> >>     Richard
>
> >> --------------------------------------------------
> >> From: "CassioT" <[email protected]>
> >> Sent: Wednesday, January 27, 2010 7:38 PM
> >> To: "nhusers" <[email protected]>
> >> Subject: [nhusers] Proxy and property modification
>
> >> > Hi all.
>
> >> > I have an entity that has a property that is defined like this:
>
> >> > public virtual decimal Amount { get; protected set; }
>
> >> > I don't know why but I can't modify it. The value never change.
>
> >> > I found two ways to fix it.
>
> >> > 1) Don't use the proxy version (fetch="join") - Never mind
> >> > 2) Remove the protected restriction
>
> >> > Am I doing something wrong or do I have any other alternative?
>
> >> > I tried to access="field" too.
>
> >> > Thanks
>
> >> > --
> >> > 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.
>
> > --
> > 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.

-- 
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