这个版本里面,因为涉及到了多库的操作,原有的系统方法不能做到这样的事情了。所以这里有了一点区别
这个类的主要用作就是,连接字符串的作用,默认是指向默认配置里面的,但是你可以指向其他的连接
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) { } } }
Entity Framework底层操作封装V2版本(4),布布扣,bubuko.com
原文地址:http://blog.csdn.net/jacky4955/article/details/25412755