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)
       { 

       }
    }
}

Entity Framework底层操作封装V2版本(4),布布扣,bubuko.com

时间: 2024-08-06 08:57:18

Entity Framework底层操作封装V2版本(4)的相关文章

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

因为同志们一直给我提建议说,以前发的版本有问题.所以经过了我这一年多的使用和扩展,现在方法基本稳定了.现在贴出来给大家使用: 首先上场的是数据库操作层: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Data.Objects.DataClasses; using System.Refl

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

这个类是真正的数据库操作类,上面的那个类只是调用了这个封装类的方法进行的操作 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Data.Entity; using System.Data.Linq; using System.Data.Objects; using System.Refl

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

现在是附加的,组合查询需要的扩展类.大家知道lanmda表达式的组合条件比较麻烦,所以就加了一样一个类,方便进行组合查询: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; namespace JFrame.AccessCommon { public static class PredicateExtensions

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

这个框架到现在最大的变化马上就要出现了,哪就是对缓存的使用.因为系统经常要去读取数据库数据,但是大家知道,数据库的处理能力是有限的,所以对于一些数据量不大,但是又 需要经常去读取的功能来说,更好的方法就是使用缓存. 上面4的方法是不适用缓存的 using System; using System.Collections.Generic; using System.Linq; using System.Text; using JFrame.AccessCommon; using System.Da

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

这个类是真正的数据库操作类.上面的那个类仅仅是调用了这个封装类的方法进行的操作 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Data.Entity; using System.Data.Linq; using System.Data.Objects; using System.Ref

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

由于同志们一直给我提建议说.曾经发的版本号有问题.所以经过了我这一年多的使用和扩展,如今方法基本稳定了. 如今贴出来给大家使用: 首先上场的是数据库操作层: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Data.Objects.DataClasses; using System.Re

MVC 基架不支持 Entity Framework 6 或更高版本 即 NuGet的几个小技巧

MVC 基架不支持 Entity Framework 6 或更高版本.有关详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=276833. 原因:mvc版本过低,ef版本过高 解决方法:1.从NuGet 卸载 ef 6.1 工具- 库程序包管理器 - 程序包管理控制台 输入PM> Uninstall-Package EntityFramework –Version 6.1.3 -Force 2.修改原语句 Install-Package <程序包名

MVC 基架不支持 Entity Framework 6 或更高版本

MVC 基架不支持 Entity Framework 6 或更高版本.有关详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=276833. PS:新做一个小型系统时,在开始打框架的时候的碰到的. 查阅了下,在我们辛勤工作的时候,EF已经升级了从EF5已经更新到了EF6了.NuGet程序包更新的时候直接更新到最新版了. 我的VS2012 最高也才MVC4 所以悲剧的不兼容了. 结论就是 MVC4+EF5  或者 MVC5+EF6 调低版本吧. 步骤如下

.NET Entity Framework入门操作

Entity Framework是微软借鉴ORM思想开发自己的一个ORM框架. ORM就是将数据库表与实体对象(相当于三层中的Model类)相互映射的一种思想. 最大的优点就是非常方便的跨数据库平台.因为该技术不需要知道用的是什么数据库,这也是.net中Linq能To任何对象的原因. 这门技术为什么可以跨平台呢?是因为它只需要修改一下config文件就可以了,只要指定连接字符串,驱动程序,就可以根据不同数据库生成不同的Sql语句,当你的项目用户用到不同的数据库时,就不需要像修改SQL语句了. E