ORM数据访问


支持,MySql/SqlServer/Oracle 任意切换,必须要改任何代码业务逻辑代码,


多数据访问实例代码

 public class ArticleDA
    {
        private static IDbDA _instance = null;
        private static readonly object SynObject = new object();

        public static IDbDA Instance
        {
            get
            {
                if (null == _instance)
                {
                    lock (SynObject)
                    {
                        if (null == _instance)
                        {
                            switch (ConfigComm._siteParm.dbType)
                            {
                                case "mysql":
                                    _instance = new MySqlServerDA();
                                    break;
                                case "sqlserver":
                                    _instance = new SqlServerDA();
                                    break;
                                case "oracle":
                                    _instance = new OracleDA();
                                    break;
                            }
                            _instance.connstr = ConfigComm._siteParm.connstr;
                        }
                    }
                }
                return _instance;
            }
        }

    } 




分页条件查询

string sql = @"  select *from plugins_plist where 1=1 and status=0 ";
            List<plugins_plist> list = ArticleDA.Instance.GetTableList<plugins_plist>(null, sql);


             sql = @"  select *from articlelist where 1=1 and status=0 ";
             search.OrderBy = " orderid desc,pId desc ";
            search.PageRecords = 20;
            search.PageIndex = 1;
            search.Page = true;
            List<Expression<Func<articlelist, bool>>> exp = new List<Expression<Func<articlelist, bool>>>();
            if (!string.IsNullOrEmpty(pName))
            {
                exp.Add(u => u.pName.Contains(pName) || u.pDetails.Contains(pName));
            }
            List<articlelist> arlist = ArticleDA.Instance.GetTableList<articlelist>(search, sql, exp);





通过主键Id获取详情


  articlelist model = ArticleDA.Instance.GetByPrimaryKey<articlelist>(pId);




新增修改


  public DynamicJsonResult ManagerDbLink(codebuild_dbconn model)
        {
            if (model.dbId > 0)
            {
                model.SetAvailableFields(new string[] { 
                    "dbType","conString","Remark"
                });
                PluginsDA.Instance.UpdateAvailableField<codebuild_dbconn>(model);
            }
            else
            {
                PluginsDA.Instance.Add<codebuild_dbconn>(model);
            }
            return new DynamicJsonResult(null,1,"成功");
        }



点击体验 免开发 平台