ActiveRecord 中的 C# 映射结构
我正在做一个小申请来帮助我平衡我的支票簿。 我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么下面的呢?还是我没听懂问题?请注意,我将结构更改为类,因为您需要虚拟成员来生成动态代理,并且结构上不能有虚拟成员。顺便说一句,为什么不使用自动实现的属性呢?
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?