SubSonic 3.0.0.3 | SimpleRepository |公式属性/字段

时间:2009-08-03 08:03:54

标签: subsonic subsonic3

我需要在SubSonic上添加公式属性/字段SimpleRepository 谁能告诉我怎么样?还是不可能?

BR, 没有身体

3 个答案:

答案 0 :(得分:2)

只需将[SubSonicIgnore]添加到LineCost上方

即可

所以

        [SubSonicIgnore]
        public decimal LineCost
        {
            get { return Qty * Convert.ToDecimal(LineCost); }
        }

这是在LineCost映射到数据库时发生的。

答案 1 :(得分:1)

为什么不在对象定义本身内进行计算?

所以

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

答案 2 :(得分:0)

我只能通过使用匿名类型看到一种方法,然后你必须将类型转换为边界线(它不是很好)

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

            }