Entity Framework底层操作封装V2版本号(4)

这个版本号里面。由于涉及到了多库的操作。原有的系统方法不能做到这种事情了。所以这里有了一点差别

这个类的主要用作就是,连接字符串的作用,默认是指向默认配置里面的,可是你能够指向其它的连接

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace JFrame.Dal
{
    public class DataBaseConnectionString
    {
        private static string _ConnectionString;
        public DataBaseConnectionString(string ConnectionString)
        {
            _ConnectionString = ConnectionString;
        }

        public static string GetConnectionString()
        {
            if (string.IsNullOrEmpty(_ConnectionString))
            {
                _ConnectionString = ConfigurationSettings.AppSettings["ConnectinString"]??"";
                if (string.IsNullOrEmpty(_ConnectionString)) 
                {
                    throw new Exception("数据库连接没有配置,请配置相关数据库连接");
                }
            }
            return "name="+_ConnectionString;
        }
    }
}


而Dal的Base类就调用这种方法进行实例化

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JFrame.AccessCommon;
using System.Data.Objects.DataClasses;

namespace JFrame.Dal
{
    public class DalBaseData<T> : AccessBase<T> where T : EntityObject 
    {
       public DalBaseData() : base(ConnectionString: DataBaseConnectionString.GetConnectionString()) { }
       
       public DalBaseData(string PrimaryKey = "", string strTableName = "", string QueryColums = "") : base(ConnectionString: DataBaseConnectionString.GetConnectionString(), PrimaryKey: PrimaryKey, strTableName: strTableName, QueryColums: QueryColums) 
       { 
            
       }
    }
}


 

 

posted on 2017-04-12 09:38  blfbuaa  阅读(123)  评论(0编辑  收藏  举报