示例#1
0
        /// <summary>
        /// Gets the connection string for the DaoContext with the specified logical name.
        /// The component will first check if any call has been made to SetContextConnectionString
        /// then check the default configuration (app.config or web.config) returning an empty string
        /// if the connection string is not found.
        /// </summary>
        /// <param name="contextName">The logical name returned by the implementation of
        /// DaoObject.ContextName.</param>
        /// <returns>A database connection string to be used for the specified logicalName.</returns>
        public static string GetContextConnectionString(string contextName)
        {
            if (contexts == null)
            {
                contexts = SingletonHelper.GetApplicationProvider <DaoContextStore>(new DaoContextStore());
            }

            if (staticConnectionStrings != null && staticConnectionStrings.ContainsKey(contextName))
            {
                return(staticConnectionStrings[contextName]);
            }

            if (contexts != null &&
                contexts.ContainsKey(contextName))
            {
                return(contexts[contextName].ConnectionString);
            }

            string property = DefaultConfiguration.GetProperty(typeof(DaoContext).Name, contextName);//CascadeConfiguration.GetProperty(logicalName, true, typeof(DaoContext));

            if (property.StartsWith("$"))
            {
                string propertyName = property.Replace("$", "");
                if (propertyName.Equals(contextName))
                {
                    throw new InvalidOperationException("Invalid DaoContext $ reference.  Must not be the same name as the context or Stack overflow will occur");
                }
                property = GetContextConnectionString(propertyName);
            }


            return(property);
        }
示例#2
0
 static DaoContext()
 {
     contexts             = SingletonHelper.GetApplicationProvider <DaoContextStore>(new DaoContextStore());//new Dictionary<string, DaoContext>();
     contextDatabaseTypes = new Dictionary <string, DaoDbType>();
 }