Beispiel #1
0
        public static IDataPersist GetDataPersist(DbProviderInfo pProviderInfo)
        {
            CommPersist commPersist = null;

            try
            {
                commPersist = PersistManeger.PersistDict[pProviderInfo.DbContextName];
            }
            catch
            {
            }
            if (commPersist == null)
            {
                BaseDbContext pDbContext;
                if (!string.IsNullOrWhiteSpace(pProviderInfo.ContextAssembly))
                {
                    List <Type> source = (
                        from tt in Assembly.LoadFrom(Path.Combine(AppSettings.BinPath, pProviderInfo.ContextAssembly)).GetTypes()
                        where tt.BaseType == typeof(BaseDbContext)
                        select tt).ToList <Type>();
                    if (string.IsNullOrWhiteSpace(pProviderInfo.ContextType))
                    {
                        source = (
                            from tt in source
                            where tt.FullName == pProviderInfo.ContextType
                            select tt).ToList <Type>();
                    }
                    Type            type        = source.FirstOrDefault <Type>();
                    ConstructorInfo constructor = type.GetConstructor(new Type[]
                    {
                        typeof(string),
                        typeof(string)
                    });
                    pDbContext = (BaseDbContext)constructor.Invoke(new object[]
                    {
                        pProviderInfo.ProviderName,
                        pProviderInfo.ConnectionString
                    });
                }
                else
                {
                    pDbContext = new NonMapDbContext(pProviderInfo.ProviderName, pProviderInfo.ConnectionString);
                }
                commPersist = new CommPersist(pDbContext, pProviderInfo.DbContextName);
                lock (PersistManeger.locker)
                {
                    PersistManeger.PersistDict[pProviderInfo.DbContextName] = commPersist;
                    CommPersist.connectionDic[pProviderInfo.DbContextName]  = pProviderInfo.ConnectionString;
                }
            }
            return(commPersist);
        }
Beispiel #2
0
        public static DbProviderInfo GetProviderInfo(string DbContextName)
        {
            if (LocalConfig.providerInfoList == null || LocalConfig.providerInfoList.Count < 1)
            {
                LocalConfig.GetProviderFromFile();
            }
            DbProviderInfo dbProviderInfo = (
                from ww in LocalConfig.providerInfoList
                where ww.DbContextName == DbContextName
                select ww).FirstOrDefault <DbProviderInfo>();

            if (dbProviderInfo == null)
            {
                IConfiger service = ServiceTaker.GetService <IConfiger>(new object[0]);
                dbProviderInfo = service.GetFirst <DbProviderInfo>(DbContextName);
                LocalConfig.providerInfoList.Remove(dbProviderInfo);
                LocalConfig.providerInfoList.Add(dbProviderInfo);
            }
            return(dbProviderInfo);
        }