zoukankan      html  css  js  c++  java
  • MVC+LINQToSQL的Repository模式之(二)数据基类

    namespace Data.TEST
    {
        /// <summary>
        /// 数据操作基类
        /// </summary>
        public abstract class TESTRepositoryBase
        {
            /// <summary>
            /// 数据库基类
            /// </summary>
            protected Entity.TEST.LinqTESTDataContext _db = (Entity.TEST.LinqTESTDataContext)DbFactory.Intance("TEST", System.Threading.Thread.CurrentThread);
            /// <summary>
            /// 统一提交动作
            /// </summary>
            protected virtual void SubmitChanges()
            {
                ChangeSet cSet = _db.GetChangeSet();
                if (cSet.Inserts.Count > 0
                    || cSet.Updates.Count > 0
                    || cSet.Deletes.Count > 0)
                {
                    try
                    {
                        _db.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                    }
                    catch (System.Data.Linq.ChangeConflictException ex)
                    {
                        foreach (System.Data.Linq.ObjectChangeConflict occ in _db.ChangeConflicts)
                        {
                            // 使用当前数据库中的值,覆盖Linq缓存中实体对象的值  
                            occ.Resolve(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
                            // 使用Linq缓存中实体对象的值,覆盖当前数据库中的值  
                            occ.Resolve(System.Data.Linq.RefreshMode.KeepCurrentValues);
                            // 只更新实体对象中改变的字段的值,其他的保留不变  
                            occ.Resolve(System.Data.Linq.RefreshMode.KeepChanges);
                        }
                        _db.SubmitChanges();
                    }
                }
            }
        }
    }

  • 相关阅读:
    WM11破解版
    安装系统
    linux配置问题
    PAT:1022. Digital Library (30) (部分正确,错最后两个)
    PAT:1023. Have Fun with Numbers (20) AC
    PAT:1081. Rational Sum (20) AC(类似math.h中的sqrt(1.0*n),algorithm的abs()用于取绝对值)
    PAT:1013. Battle Over Cities (25) AC
    conv2的计算过程
    UFLDL Tutorial
    视频深度学习 Deep Learning
  • 原文地址:https://www.cnblogs.com/sjqq/p/9123124.html
Copyright © 2011-2022 走看看