Question

I need to add Formula property/field on SubSonic | SimpleRepository Can someone tell me how to? or is it not possible?

br, No Body

Was it helpful?

Solution

Just add [SubSonicIgnore] to above LineCost

so

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

this is happening as LineCost is being mapped to the database.

OTHER TIPS

Why not just do the calculation within the object definition itself?

So

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

I can only see a way by using anoynmous types, and then you will have to convert the type to the orderline (its not very nice)

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

            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top