ActiveRecord 中的 C# 映射结构

发布于 2024-08-20 09:12:18 字数 1119 浏览 2 评论 0原文

我正在做一个小申请来帮助我平衡我的支票簿。 我正在使用 Castle ActiveRecord 将对象属性映射到数据库。现在问题来了。当我制作一个货币程序时,我创建了一个结构体Currency

结构体:

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

我正在映射的类:

[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; }
    }
}

现在在理想情况下,Currency 对象的行为就像一个嵌套对象,因此 amount 和currencyType 是交易表中的两列。 但它不是嵌套的视图,因为我希望它像货币结构对象一样。

我不知道我应该给货币金额赋予什么标签才能使其发挥作用,如果有人可以帮助我解决这个问题,我将非常感激。

我希望这一切都清楚。

格雷因斯·邓肯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱的那么颓废 2024-08-27 09:12:18

那么下面的呢?还是我没听懂问题?请注意,我将结构更改为类,因为您需要虚拟成员来生成动态代理,并且结构上不能有虚拟成员。顺便说一句,为什么不使用自动实现的属性呢?

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

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; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文