首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SubSonic 3.0.0.3 | SimpleRepository |公式属性/字段

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

Stack Overflow用户
提问于 2009-08-03 08:03:54
回答 3查看 132关注 0票数 0

我需要在SubSonic | SimpleRepository上添加公式属性/字段。有人能告诉我怎么做吗?或者这是不可能的?

br,无主体

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-08-03 12:16:25

只需在上面的LineCost中添加SubSonicIgnore

所以

代码语言:javascript
复制
        [SubSonicIgnore]
        public decimal LineCost
        {
            get { return Qty * Convert.ToDecimal(LineCost); }
        }

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

票数 2
EN

Stack Overflow用户

发布于 2009-08-03 11:00:58

为什么不直接在对象定义中进行计算呢?

所以

代码语言:javascript
复制
    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); }
        }
    }
票数 1
EN

Stack Overflow用户

发布于 2009-08-04 08:35:15

我只能通过使用无序类型找到一种方法,然后你必须将类型转换为orderline (这不是很好)

代码语言:javascript
复制
                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
                });

            }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1221151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档