serenity-is / Serenity

Business Apps Made Simple with Asp.Net Core MVC / TypeScript
https://serenity.is
MIT License
2.6k stars 802 forks source link

grid showed sum value #3007

Closed dxh141130 closed 6 years ago

dxh141130 commented 6 years ago

I have primary table order and sub table order detail, one order has mutilple order detail. i want to show the order amount is sum of several order detail amount in order grid. i tried to use expression, but i can not use group by. and i tried to use formatter, editor. I donot know what kind of reason, it does not show error, but the order grid did not show sum order detail amount. Please give me an example about that ,thanks

Zahar661 commented 6 years ago

in OrderRow [Expression("Select SUM(Summa) from [OrderDetail] AS T1 WHERE T0.OrderId = T1.OrderId")] ...... [Expression("Select Count(DetailId) from [OrderDetail] AS T1 WHERE T0.OrderId = T1.OrderId")] .......

Zahar661 commented 6 years ago

in Nortwind Order

[DisplayName("Summ"), Expression("(Select SUM(t1.[UnitPrice] * t1.[Quantity] - t1.[Discount]) from [Order Details] AS t1 WHERE T0.OrderId = t1.OrderId)")]
        public Decimal? Summ
        {
            get { return Fields.Summ[this]; }
            set { Fields.Summ[this] = value; }
        }

image

Zahar661 commented 6 years ago

and count

[DisplayName("Count"), Expression("(Select Count(t1.[DetailID]) from [Order Details] AS t1 WHERE T0.OrderId = t1.OrderId)")]
        public Decimal? Count
        {
            get { return Fields.Count[this]; }
            set { Fields.Count[this] = value; }
        }

image

dxh141130 commented 6 years ago

Thank you so much. i used to think what i can do is work on one row, now it looks i could write sql query to a field. MANY THANKS