views:

156

answers:

1

Hi here. i am making a little application to help me balance my checkbook. i am using Castle ActiveRecord to map the object properties to the database. now here is the problem. as i am making a money program i made a struct Currency

The struct:

public struct Currency
{
    private long amount;
    private CurrencyType currencyType;

    public long Amount
    {
        get { return this.amount; }
        set { this.amount = value; }
    }

    public CurrencyType CurrencyType
    {
        get { return this.currencyType; }
        set { this.currencyType = value; }
    }
}

The class i am mapping:

[ActiveRecord("[Transaction]")]
public class Transaction: HasOwnerModelBase
{
    private Currency amount;
    private Category category;

    [BelongsTo]
    public virtual Category Category
    {
        get { return this.category; }
        set { this.category = value; }
    }

    public virtual Currency Amount
    {
        get { return this.amount; }
        set { this.amount = value; }
    }
}

Now in the ideal situation the Currency object would act like a nested object so the amount and currencyType are two colums in the transaction table. but it is not a nested seeing as i want it to act like the currency struct object.

I have no idea what tag i should give the Currency Amount for it to work, i would really appreciate it if any one could help me solve this problem.

I hope all of this is clear.

Greatings Duncan

+2  A: 

What about the following? Or didn't I get the question? Note that I changed the structure to a class because you need virtual members for dynamic proxy generation and you cannot have virtual members on structures. By the way, why don't you use auto-implemented properties?

public class Currency
{
    [Property]
    public virtual Int64 Amount { get; set; }   

    [Property]
    public virtual CurrencyType CurrencyType { get; set; }
}

[ActiveRecord("[Transaction]")]
public class Transaction: HasOwnerModelBase
{
    [BelongsTo]
    public virtual Category Category { get; set; }

    [Nested]  
    public virtual Currency Amount { get; set; }
}
Daniel Brückner
Well the virtual stuff i know my bad but not really important for this example.the auto property thing is that at work we still have to use the vs2005 so not used to it yet ;)the nested is indeed a good idea but i already tough of that. i can't really test it now, but i am pretty sure that the object is get when i pull a transaction from the database is not a currency object. if so. i am really stupid
LordSauron
It should be an instance of your Currency class or of a dynamic proxy derived from Currency depending on whether you are using transparent lazy loading or not.
Daniel Brückner
I will try this out tomorrow when i can test it properly. will update thanx for the help so fare!
LordSauron
+1 Nested is the way to go. BTW I don't think components are proxied.
Mauricio Scheffer