当前位置: 首页>>代码示例>>C#>>正文


C# EntityClient.EntityConnectionStringBuilder类代码示例

本文整理汇总了C#中System.Data.EntityClient.EntityConnectionStringBuilder的典型用法代码示例。如果您正苦于以下问题:C# EntityConnectionStringBuilder类的具体用法?C# EntityConnectionStringBuilder怎么用?C# EntityConnectionStringBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EntityConnectionStringBuilder类属于System.Data.EntityClient命名空间,在下文中一共展示了EntityConnectionStringBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateEntityConnectionWithWrappers

        /// <summary>
        /// Creates the entity connection with wrappers.
        /// </summary>
        /// <param name="entityConnectionString">The original entity connection string.</param>
        /// <param name="wrapperProviders">List for wrapper providers.</param>
        /// <returns>EntityConnection object which is based on a chain of providers.</returns>
        public static EntityConnection CreateEntityConnectionWithWrappers(string entityConnectionString, params string[] wrapperProviders)
        {
            EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder(entityConnectionString);

            // if connection string is name=EntryName, look up entry in the config file and parse it
            if (!String.IsNullOrEmpty(ecsb.Name))
            {
                var connStr = System.Configuration.ConfigurationManager.ConnectionStrings[ecsb.Name];
                if (connStr == null)
                {
                    throw new ArgumentException("Specified named connection string '" + ecsb.Name + "' was not found in the configuration file.");
                }

                ecsb.ConnectionString = connStr.ConnectionString;
            }

            MetadataWorkspace workspace;
            if (!metadataWorkspaceMemoizer.TryGetValue(ecsb.ConnectionString, out workspace))
            {
                workspace = CreateWrappedMetadataWorkspace(ecsb.Metadata, wrapperProviders);
                metadataWorkspaceMemoizer.Add(ecsb.ConnectionString, workspace);
            }

            var storeConnection = DbProviderFactories.GetFactory(ecsb.Provider).CreateConnection();
            storeConnection.ConnectionString = ecsb.ProviderConnectionString;
            var newEntityConnection = new EntityConnection(workspace, DBConnectionWrapper.WrapConnection(storeConnection, wrapperProviders));
            return newEntityConnection;
        }
开发者ID:peisheng,项目名称:EASYFRAMEWORK,代码行数:34,代码来源:EntityConnectionWrapperUtils.cs

示例2: GetEntityConnectionString

        /// <summary>
        /// Retrieves and builds an entity connection string given one specified in web.config.
        /// </summary>
        /// <returns>Connection String for a store that is intended to host tokens.</returns>
        internal static string GetEntityConnectionString()
        {
            string cs = string.Empty;
            System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyWebSiteRoot");
            System.Configuration.ConnectionStringSettings connString;

            if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
            {
                connString = rootWebConfig.ConnectionStrings.ConnectionStrings["AppTokenStorage"];

                if (connString != null)
                {
                    cs = connString.ConnectionString;
                }
                else
                {
                    throw new Exception("No connection string named 'AppTokenStorage' was declared in web.config.");
                }
            }

            EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder();

            ecsb.ProviderConnectionString = cs + ";MultipleActiveResultSets=True;Application Name=EntityFramework";
            ecsb.Provider = "System.Data.SqlClient";
            ecsb.Metadata = "res://*/TokenStore.csdl|res://*/TokenStore.ssdl|res://*/TokenStore.msl";

            return ecsb.ToString();
        }
开发者ID:mammerla,项目名称:ServerIntegration,代码行数:32,代码来源:TokenUtilities.cs

示例3: GetEntitiesContext

        public HERBProject_DataBaseEntities GetEntitiesContext()
        {
            // Initialize Entity Connection String Builder
            EntityConnectionStringBuilder entityConnectionStringBuilder = new EntityConnectionStringBuilder();

            // Set the provider name
            entityConnectionStringBuilder.Provider = "System.Data.SqlClient";

            // Set the provider-specific connection string
            entityConnectionStringBuilder.ProviderConnectionString = _connectionString;
            entityConnectionStringBuilder.ProviderConnectionString += ";MultipleActiveResultSets=True";

            // Set the Metadata location
            entityConnectionStringBuilder.Metadata = string.Format("{0}|{1}|{2}",
                                            "res://*/Repositories.CustomBoundedRepository.HERBProject_DataBase.csdl",
                                            "res://*/Repositories.CustomBoundedRepository.HERBProject_DataBase.ssdl",
                                            "res://*/Repositories.CustomBoundedRepository.HERBProject_DataBase.msl");

            // Build Entity Connection
            EntityConnection entityConnection = new EntityConnection(entityConnectionStringBuilder.ToString());

            // Initialize Entity Object
            return new HERBProject_DataBaseEntities(entityConnection)
            {
                CommandTimeout = _commandTimeOut
            };
        }
开发者ID:jcgonzalezalzate,项目名称:HerbProject,代码行数:27,代码来源:CustomBoundedContext.cs

示例4: CreateConnectionString

            protected override string CreateConnectionString()
            {              
                // Specify the provider name, server and database.
                string providerName = "System.Data.SqlClient";
                string serverName = ".\\SQLEXPRESS";
                string databaseName = "ZMTdb";

                // Initialize the connection string builder for the
                // underlying provider.
                SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();

                // Set the properties for the data source.
                sqlBuilder.DataSource = serverName;
                sqlBuilder.InitialCatalog = databaseName;
                sqlBuilder.IntegratedSecurity = true;

                // Build the SqlConnection connection string.
                string providerString = sqlBuilder.ToString();

                // Initialize the EntityConnectionStringBuilder.
                EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();

                //Set the provider name.
                entityBuilder.Provider = providerName;

                // Set the provider-specific connection string.
                entityBuilder.ProviderConnectionString = providerString;

                // Set the Metadata location.
                entityBuilder.Metadata = @"res://EF_ZMTdbConnection/EF_ZMTdbModel.csdl|res://EF_ZMTdbConnection/EF_ZMTdbModel.ssdl|res://EF_ZMTdbConnection/EF_ZMTdbModel.msl";
                return entityBuilder.ToString();
            }
开发者ID:pawelsorsa,项目名称:Fixed-Assets-System,代码行数:32,代码来源:EF_ZMT_DbContext.cs

示例5: Create

        public static void Create()
        {
            using (YomContainer container = new YomContainer())
            {
                container.Database.Create();
            }

            string connectionstring = ConfigurationManager.ConnectionStrings["YomContainer"].ConnectionString;

            EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder(connectionstring);

            string providerconnectionstring = builder.ProviderConnectionString;

            Process process = new Process();
            process.StartInfo.FileName = @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regsql.exe";
            process.StartInfo.Arguments = string.Format("-A mr  -C \"{0}\"", providerconnectionstring);
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;

            process.Start();

            Console.WriteLine(process.StandardOutput.ReadToEnd());

            Console.ReadKey();
        }
开发者ID:mpodonyi,项目名称:Yom,代码行数:25,代码来源:Database.cs

示例6: GetEntityFrameworkConnectionString

        /// <summary>
        /// Gets the entity framework connection string.
        /// </summary>
        /// <param name="contextType">Type of the context.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <returns>The entity framework connection string.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="contextType"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The <paramref name="connectionString" /> is <c>null</c> or whitespace.</exception>
        public static string GetEntityFrameworkConnectionString(Type contextType, string connectionString)
        {
            Argument.IsNotNull("contextType", contextType);
            Argument.IsNotNullOrWhitespace("connectionString", connectionString);

            if (connectionString.Contains("res://"))
            {
                // already EF connection string
                return connectionString;
            }

            var fullName = contextType.FullName;
            if (fullName.EndsWith("Container"))
            {
                fullName = fullName.Substring(0, fullName.Length - "Container".Length);
            }

            var assemblyNameParts = contextType.Assembly.GetName().Name.Split(new[] { '.' });
            foreach (var assemblyNamePart in assemblyNameParts)
            {
                string itemToReplace = string.Format("{0}.", assemblyNamePart);
                if (fullName.StartsWith(itemToReplace))
                {
                    fullName = fullName.Remove(0, itemToReplace.Length);
                }
            }

            var connectionBuilder = new EntityConnectionStringBuilder();
            connectionBuilder.Provider = "System.Data.SqlClient";
            connectionBuilder.Metadata = string.Format("res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl", fullName);

            connectionBuilder.ProviderConnectionString = connectionString;

            return connectionBuilder.ToString();
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:43,代码来源:EfConnectionStringHelper.cs

示例7: Page_Load

    //-------------------------------------------------------------------------------------------
    protected void Page_Load(object sender, EventArgs e)
    {
        IsPublic = true;

          if (Request.UserHostAddress != "127.0.0.1" || ConfigurationManager.AppSettings["install_mode"] == "false")
          {
               Response.Write("This page is unavailable to the general internet. Please visit from the server machine.");
               Response.End();
          }

          WeavverMaster.SetToolbarVisibility(false);
          WeavverMaster.FormTitle = "Weavver First-Time Set-Up";
          WeavverMaster.FormDescription = "This wizard will help you configure Weavver for your first use.";

          //"Notice: To deploy the schema you need to change your web.config setting 'install_mode' from false to true to install Weavver.";

          //NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration cfg = (NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration)ConfigurationManager.GetSection("hibernate-configuration");
          //string con1 = ConfigurationManager.ConnectionStrings["weavver"].ConnectionString;
          //string con2 = cfg.SessionFactory.Properties["connection.connection_string"];
          //if (con1 != con2)
          //{
          //     ShowError("Your connection strings are out of sync. Please fix this in the web.config file.");
          //}

          string connectionString = ConfigurationManager.ConnectionStrings["WeavverEntityContainer"].ConnectionString;
          var entityBuilder = new System.Data.EntityClient.EntityConnectionStringBuilder(connectionString);
          var sqlBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder(entityBuilder.ProviderConnectionString);
          DatabaseHost.Text = sqlBuilder.DataSource;
          DatabaseUsername.Text = sqlBuilder.UserID;
          DatabaseName.Text = sqlBuilder.InitialCatalog;
    }
开发者ID:weavver,项目名称:weavver,代码行数:32,代码来源:Default.aspx.cs

示例8: DbConnectAsync

        // Метод для асинхронного создания подключения к БД
        private async Task<bool> DbConnectAsync(string dbname)
        {                        
            try
            {
                // Создаем строку подключения
                EntityConnectionStringBuilder ConnectionString = new EntityConnectionStringBuilder();
                ConnectionString.ProviderConnectionString = "data source=" + Uchet.Properties.Settings.Default.dbDir
                                                             + dbname;
                ConnectionString.Provider = Uchet.Properties.Settings.Default.dbProvider;
                ConnectionString.Metadata = @Uchet.Properties.Settings.Default.dbMetadata;

                // Асинхронно создаем подключение
                await Task.Run(() => { 
                    this.DB = new DBEntity(ConnectionString.ToString());                    

                    // Задаем DataSource для таблиц в соответствии с таблицами БД приложения  
                    this.Invoke((Action)delegate{
                        gearCountEntityBindingSource.DataSource = DB.GC.ToList<GearCountEntity>();
                        gearCountEntityBindingSource.DataSource = DB.GC.Local.ToBindingList<GearCountEntity>();
                        gearPriceEntityBindingSource.DataSource = DB.GP.ToList<GearPriceEntity>();
                        gearSumEntityBindingSource.DataSource = DB.GS.ToList<GearSumEntity>();
                        gearSumEntityBindingSource.DataSource = DB.GS.Local.ToBindingList<GearSumEntity>();                    
                    });                    
                });                

                return true;
            }

            catch (Exception exeption)
            {                
                MessageBox.Show(exeption.Message, "Ошибка!");
            }

            return false;
        }
开发者ID:8bit-cat,项目名称:archive,代码行数:36,代码来源:MainForm.cs

示例9: DBConnection

        public DBConnection()
        {
            // Specify the provider name, server and database.

            // Initialize the connection string builder for the
            // underlying provider.
            SqlConnectionStringBuilder sqlBuilder =
                new SqlConnectionStringBuilder();

            // Set the properties for the data source.
            sqlBuilder.DataSource = serverName;
            sqlBuilder.InitialCatalog = databaseName;
            sqlBuilder.IntegratedSecurity = true;

            // Build the SqlConnection connection string.
            string providerString = sqlBuilder.ToString();

            // Initialize the EntityConnectionStringBuilder.
            EntityConnectionStringBuilder entityBuilder =
                new EntityConnectionStringBuilder();

            //Set the provider name.
            entityBuilder.Provider = providerName;

            // Set the provider-specific connection string.
            entityBuilder.ProviderConnectionString = providerString;

            // Set the Metadata location.
            entityBuilder.Metadata [email protected]"res://*/ShoeShopEntity.csdl|res://*/ShoeShopEntity.ssdl|res://*/ShoeShopEntity.msl";

            entity = new SHOESHOPEntities(entityBuilder.ToString());
        }
开发者ID:sumutcan,项目名称:WTWP-E-Commerce-ShoeShop,代码行数:32,代码来源:DBConnection.cs

示例10: GetConnectionString

        public string GetConnectionString(string connection)
        {
            string connectionString = connection;

            try
            {
                DataConnectionConfiguration dcs = new DataConnectionConfiguration(null);
                DataConnectionDialog dcd = new DataConnectionDialog();

                //EF CONN STR to SQL CONNECTION
                EntityConnectionStringBuilder efstr = new EntityConnectionStringBuilder(connection);

                dcs.LoadConfiguration(dcd);
                dcd.ConnectionString = efstr.ProviderConnectionString;

                if (DataConnectionDialog.Show(dcd) == System.Windows.Forms.DialogResult.OK)
                {
                    connectionString = dcd.ConnectionString;
                }
                dcs.SaveConfiguration(dcd);

                //SQL CONNECTION TO EF CONN STR
                SqlConnectionStringBuilder sqlstr = new SqlConnectionStringBuilder(dcd.ConnectionString);
                efstr.ProviderConnectionString = sqlstr.ConnectionString;
                connectionString = efstr.ConnectionString;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return connectionString;
        }
开发者ID:hprog,项目名称:exchange,代码行数:34,代码来源:ConnectionSettings.cs

示例11: CreateFromEFConnectionString

 public static ResetDatabase CreateFromEFConnectionString(string efConnStr)
 {
     var builder = new EntityConnectionStringBuilder(efConnStr);
     var connStr = builder.ProviderConnectionString;
     var conn = new SqlConnectionAdapterUsingSqlConnection(new SqlConnection(connStr));
     return new ResetDatabase(conn);
 }
开发者ID:hwinkel,项目名称:dotnet-coffeeshop,代码行数:7,代码来源:ResetDatabase.cs

示例12: CreateEntityConnectionWithWrappers

        /// <summary>
        /// Creates the entity connection with wrappers.
        /// </summary>
        /// <param name="entityConnectionString">The original entity connection string. This may also be a single word, e.g., "MyEntities", in which case it is translated into "name=MyEntities" and looked up in the application configuration.</param>
        /// <param name="wrapperProviders">List for wrapper providers.</param>
        /// <returns>EntityConnection object which is based on a chain of providers.</returns>
        public static EntityConnection CreateEntityConnectionWithWrappers(string entityConnectionString, params string[] wrapperProviders)
        {
            // If there is only a single word in the connection string, treat it as the value for Name.
            if (!entityConnectionString.Contains('='))
                entityConnectionString = "name=" + entityConnectionString;

            EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder(entityConnectionString);

            // if connection string is name=EntryName, look up entry in the config file and parse it
            if (!String.IsNullOrEmpty(ecsb.Name))
            {
                var connStr = ConfigurationManager.ConnectionStrings[ecsb.Name];
                if (connStr == null)
                {
                    throw new ArgumentException("Specified named connection string '" + ecsb.Name + "' was not found in the configuration file.");
                }

                ecsb.ConnectionString = connStr.ConnectionString;

            }

            var workspace = metadataWorkspaceMemoizer.GetOrAdd(ecsb.ConnectionString, _ => CreateWrappedMetadataWorkspace(ecsb.Metadata, wrapperProviders));
            var storeConnection = DbProviderFactories.GetFactory(ecsb.Provider).CreateConnection();
            storeConnection.ConnectionString = ecsb.ProviderConnectionString;
            var newEntityConnection = new EntityConnection(workspace, DbConnectionWrapper.WrapConnection(storeConnection, wrapperProviders));
            return newEntityConnection;
        }
开发者ID:jokingzhou,项目名称:AnJi-DevZoneGIS,代码行数:33,代码来源:EntityConnectionWrapperUtils.cs

示例13: GetEntityBuilder

        private EntityConnectionStringBuilder GetEntityBuilder()
        {
            SqlConnectionStringBuilder sqlBuilder =
                new SqlConnectionStringBuilder();

            // Set the properties for the data source.
            sqlBuilder.DataSource = serverName;
            sqlBuilder.InitialCatalog = databaseName;
            sqlBuilder.IntegratedSecurity = true;
            //sqlBuilder.UserID = user;
            //sqlBuilder.Password = pwd;

            // Build the SqlConnection connection string.
            string providerString = sqlBuilder.ToString();

            // Initialize the EntityConnectionStringBuilder.
            EntityConnectionStringBuilder entityBuilder =
                new EntityConnectionStringBuilder();

            //Set the provider name.
            entityBuilder.Provider = providerName;

            // Set the provider-specific connection string.
            entityBuilder.ProviderConnectionString = providerString;

            // Set the Metadata location.
            entityBuilder.Metadata = @"res://*/MyEntities.csdl|
                            res://*/MyEntities.ssdl|
                            res://*/MyEntities.msl";
            return entityBuilder;
        }
开发者ID:Letractively,项目名称:henoch,代码行数:31,代码来源:Repository.cs

示例14: ConnectionString

        public ConnectionString(IConfigurationManager configuration, string name, string edmFilesPath,
            string ssdlFileName, string csdlFileName, string mslFileName)
        {
            if(String.IsNullOrEmpty(edmFilesPath))
            {
                edmFilesPath=_demFilesPath;
            }

            if(String.IsNullOrEmpty(ssdlFileName))
            {
                ssdlFileName=_ssdlFileName;
            }

            if(String.IsNullOrEmpty(csdlFileName))
            {
                csdlFileName=_csdlFileName;
            }
            if(String.IsNullOrEmpty(mslFileName))
            {
                mslFileName=_mslFileName;
            }

            string providerConnectionString=configuration.GetConnectionString(name);
            string providerName=configuration.GetProviderName(name);
            string metadata = String.Format(CultureInfo.InvariantCulture,
                _demMetadataFormat, edmFilesPath, csdlFileName, ssdlFileName, mslFileName);
            _entityBuilder = new EntityConnectionStringBuilder
            {
                ProviderConnectionString = providerConnectionString,
                Provider = providerName,
                Metadata = metadata
            };
        }
开发者ID:xxfss2,项目名称:Cat,代码行数:33,代码来源:ConnectionString.cs

示例15: Page_Load

        // Обработчик загрузки страницы
        protected void Page_Load(object sender, EventArgs e)
        {            
            // Формируем список городов для просмотра 
            // погодных данных            
            CityList.Add(new City("Челябинск", 0));
            CityList.Add(new City("Москва", 1));
            CityList.Add(new City("Самара", 2));

            // Формируем список погодных сервисов            
            EntityConnectionStringBuilder ConnectionString =
                new EntityConnectionStringBuilder();
            ConnectionString.ProviderConnectionString =
                @"data source=|DataDirectory|YahooWeatherDB.sqlite";
            ConnectionString.Provider = @"System.Data.SQLite";
            ConnectionString.Metadata =
                @"res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl";
            WeatherServiceList.Add(new WeatherService("Yahoo! Weather",
                ConnectionString.ToString()));
            ConnectionString.ProviderConnectionString =
                @"data source=|DataDirectory|YandexWeatherDB.sqlite";
            WeatherServiceList.Add(new WeatherService("Яндекс Погода",
                ConnectionString.ToString()));

            // Привязываем список городов и погодных сервисов
            // к элементам интерфейса            
            foreach (City item in CityList)            
                if (!CityDropDownList.Items.Contains(new ListItem(item.Name)))
                    CityDropDownList.Items.Add(new ListItem(item.Name));                       
            foreach (var item in WeatherServiceList)
                if (!ServiceDropDownList.Items.Contains(new ListItem(item.Name)))
                    ServiceDropDownList.Items.Add(new ListItem(item.Name));                
        }
开发者ID:8bit-cat,项目名称:archive,代码行数:33,代码来源:Default.aspx.cs


注:本文中的System.Data.EntityClient.EntityConnectionStringBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。