【发布时间】:2009-08-03 08:03:53
【问题描述】:
我需要在 SubSonic | 上添加公式属性/字段简单存储库 有人能告诉我怎么做吗?还是不可能?
br, 没有身体
【问题讨论】:
我需要在 SubSonic | 上添加公式属性/字段简单存储库 有人能告诉我怎么做吗?还是不可能?
br, 没有身体
【问题讨论】:
只需将 [SubSonicIgnore] 添加到上面的 LineCost
所以
[SubSonicIgnore]
public decimal LineCost
{
get { return Qty * Convert.ToDecimal(LineCost); }
}
这是在 LineCost 被映射到数据库时发生的。
【讨论】:
为什么不在对象定义本身内进行计算?
所以
public class OrderLine
{
public int OrderId { get; set; }
public int Qty { get; set; }
public decimal ProductPrice { get; set; }
public decimal LineCost
{
get { return Qty * Convert.ToDecimal(LineCost); }
}
}
【讨论】:
我只能看到使用匿名类型的方法,然后您必须将类型转换为订单线(它不是很好)
var x =from o in repo.All<OrderLine>()
select new
{
OrderId = o.OrderId,
ProductPrice = o.ProductPrice,
Qty = o.Qty,
LineCost = o.ProductPrice * o.Qty
};
List<OrderLine> orders = null;
foreach (var t in x)
{
orders.Add(new OrderLine
{
LineCost = t.LineCost,
OrderId = t.OrderId,
ProductPrice = t.ProductPrice,
Qty = t.Qty
});
}
【讨论】: