zoukankan      html  css  js  c++  java
  • Bitter.Core系列十一:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore 之 字段变更收集器

    有时候我们业务层需要记录 数据库表更改之前的值和更改之后的值的记录集合--此过程在 Bitter.Core 中有强有力的支持。Bitter.Core 字段收集器提供了方便简单易用的 收集对象在修改之前和修改之后所有对象内字段变更记录的集合。当然,如果涉及

    没有变更的字段,将不会显示在变更记录集合中。示例代码如下:

    /// <summary>
            /// 字段变更收集器
            /// </summary>
            public static void FildUpdateCollector()
            {
                // 根据ID 查询:
                var student = db.FindQuery<TStudentInfo>().QueryById(12); //只有数据库模型中的 virtual 字段 才能支持字段变更.
                if (student.FID > 0)
                {
                   
                    var stduentproxy= student.CreateModelProxy(); //转化数据库模型代理实例
                    stduentproxy.FAage = 60;
                    stduentproxy.FName = "名字变了";
                    var updatefiledlist = stduentproxy.GetChangedInfo(); //返回了对象实例字段变更集合.至于收集到的updatefiledlist用于处理什么业务,那是业务层的事情.
                    stduentproxy.Update().Submit();//提交到数据库
                }
            }


    看了上面的代码,让字段变更收集变得相当的容易.

  • 相关阅读:
    leetcode 18 4Sum
    leetcode 71 Simplify Path
    leetcode 10 Regular Expression Matching
    leetcode 30 Substring with Concatenation of All Words
    leetcode 355 Design Twitte
    leetcode LRU Cache
    leetcode 3Sum
    leetcode Letter Combinations of a Phone Number
    leetcode Remove Nth Node From End of List
    leetcode Valid Parentheses
  • 原文地址:https://www.cnblogs.com/davidchildblog/p/14303930.html
Copyright © 2011-2022 走看看