• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# EntityClient.EntityConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



EntityConnection类属于System.Data.EntityClient命名空间,在下文中一共展示了EntityConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: UpdateTranslator

        /// <summary>
        /// Constructs a grouper based on the contents of the given entity state manager.
        /// </summary>
        /// <param name="stateManager">Entity state manager containing changes to be processed.</param>
        /// <param name="metadataWorkspace">Metadata workspace.</param>
        /// <param name="connection">Map connection</param>
        /// <param name="commandTimeout">Timeout for update commands; null means 'use provider default'</param>
        private UpdateTranslator(IEntityStateManager stateManager, MetadataWorkspace metadataWorkspace, EntityConnection connection, int? commandTimeout)
        {
            EntityUtil.CheckArgumentNull(stateManager, "stateManager");
            EntityUtil.CheckArgumentNull(metadataWorkspace, "metadataWorkspace");
            EntityUtil.CheckArgumentNull(connection, "connection");

            // propagation state
            m_changes = new Dictionary<EntitySetBase, ChangeNode>();
            m_functionChanges = new Dictionary<EntitySetBase, List<ExtractedStateEntry>>();
            m_stateEntries = new List<IEntityStateEntry>();
            m_knownEntityKeys = new Set<EntityKey>();
            m_requiredEntities = new Dictionary<EntityKey, AssociationSet>();
            m_optionalEntities = new Set<EntityKey>();
            m_includedValueEntities = new Set<EntityKey>();

            // workspace state
            m_metadataWorkspace = metadataWorkspace;
            m_viewLoader = metadataWorkspace.GetUpdateViewLoader();
            m_stateManager = stateManager;

            // ancillary propagation services
            m_recordConverter = new RecordConverter(this);
            m_constraintValidator = new RelationshipConstraintValidator(this);

            m_providerServices = DbProviderServices.GetProviderServices(connection.StoreProviderFactory);
            m_connection = connection;
            m_commandTimeout = commandTimeout;

            // metadata cache
            m_extractorMetadata = new Dictionary<Tuple<EntitySetBase, StructuralType>, ExtractorMetadata>(); ;

            // key management
            KeyManager = new KeyManager(this);
            KeyComparer = CompositeKey.CreateComparer(KeyManager);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:42,代码来源:UpdateTranslator.cs


示例3: Main

        static void Main(string[] args)
        {
            using (var c = new EntityConnection("name=AdventureWorksEntities"))
            {
                c.StateChange += EStateChange;

                var cmd = "SELECT VALUE C FROM AdventureWorksEntities.Contatos AS C WHERE [email protected]";

                using (var k = new EntityCommand(cmd, c))
                {
                    k.Parameters.AddWithValue("ContactID", 1);

                    c.Open();

                    var dr = k.ExecuteReader(CommandBehavior.SequentialAccess);

                    if (dr.Read()) //while se existir mais de um registro
                    {
                        Console.WriteLine(dr["Nome"]);
                    }

                    if (c.State != ConnectionState.Closed) c.Close();
                }
            }

            Console.ReadKey();
        }
开发者ID:50minutos,项目名称:MOC-10265,代码行数:27,代码来源:Program.cs


示例4: GetEntityConnection

 private EntityConnection GetEntityConnection()
 {
   string connectionString = String.Format(
       "metadata=TestDB.csdl|TestDB.msl|TestDB.ssdl;provider=MySql.Data.MySqlClient; provider connection string=\"{0}\"", GetConnectionString(true));
   EntityConnection connection = new EntityConnection(connectionString);
   return connection;
 }
开发者ID:jimmy00784,项目名称:mysql-connector-net,代码行数:7,代码来源:CanonicalFunctions.cs


示例5: Test1

        public void Test1()
        {
            string SELECT_PERSONS_ALL = "SELECT p.id as person_id, p.fname, p.lname, ph.id as phone_id , " +
                "ph.phonevalue as phonevalue, a.id as address_id , a.addressvalue as addressvalue " +
                "FROM Entities.People as p INNER JOIN Entities.Addresses as a ON a.personid = p.id " +
                "INNER JOIN Entities.Phones as ph ON ph.personid = p.id";

            EntityConnection m_connection = new EntityConnection("name=Entities");
            List<Mock.PhoneBook.Phone> list = new List<Mock.PhoneBook.Phone>();

            m_connection.Open();
            Infrastructure.PhoneBook.IMockConvertor convertor = new ERDBArch.Modules.PhoneBook.BLL.PersonConvertor();

            using (EntityCommand cmd = new EntityCommand(SELECT_PERSONS_ALL, m_connection))
            {
                using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                {
                    while (reader.Read())
                    {
                        System.Diagnostics.Debug.WriteLine(reader["person_id"]);

                    }
                }
            }
            m_connection.Close();
        }
开发者ID:alexei-reb,项目名称:ERDBArch,代码行数:26,代码来源:Class2.cs


示例6: 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


示例7: 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


示例8: GetClubAutoComplete

        public IList<Club> GetClubAutoComplete(string searchText)
        {
            var clubs = new List<Club>();

            using (var connection = new EntityConnection("name=CoreContainer"))
            {
                _core = new CoreContainer(connection);

                if(searchText.Equals("**"))
                {
                    clubs = _core.Clubs
                                    .Where(c => c.DateActivated.HasValue
                                                && !c.DateCancelled.HasValue)
                                    .OrderBy(c => c.FullName)
                                    .ToList();
                }
                else
                {
                    clubs = _core.Clubs
                                    .Where(c => c.DateActivated.HasValue
                                                && !c.DateCancelled.HasValue
                                                && (c.FullName.ToLower().Contains(searchText)
                                                || c.Acronym.ToLower().Contains(searchText)))
                                    .OrderBy(c => c.FullName)
                                    .ToList();
                }
            }

            return clubs;
        }
开发者ID:jimgaryphoenix,项目名称:Sierra12,代码行数:30,代码来源:ClubRepository.cs


示例9: ReadContents

        public static void ReadContents()
        {
            using (EntityConnection cn = new EntityConnection("name=DESEDMEntities"))
            {
                cn.Open();

                string query = "SELECT VALUE DESContent FROM DESEDMEntities.DESContents AS DESContent";

                using (EntityCommand cmd = cn.CreateCommand())
                {
                    cmd.CommandText = query;

                    // Finally, get the data reader and process records.
                    using (EntityDataReader dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        Console.WriteLine("Count: " + dr.FieldCount);
                        Console.WriteLine("Row:" + dr.HasRows);

                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                Console.WriteLine("****RECORD*****");
                                Console.WriteLine("ID: {0}", dr["Id"]);
                                Console.WriteLine("Input File Name: {0}", dr["InputFileName"]);
                                Console.WriteLine("Output File Name: {0}", dr["OutputFileName"]);
                            }
                        }
                    }
                }
            }
        }
开发者ID:jazziiilove,项目名称:Crypto-.NET,代码行数:32,代码来源:EDM.cs


示例10: AddTeam

        public void AddTeam(string name, string email, bool isExclusive, bool isActive)
        {

            // Initialize the connection string builder for the
            // underlying provider.
            EntityConnectionStringBuilder entityBuilder = GetEntityBuilder();

            using (EntityConnection conn =
                    new EntityConnection(entityBuilder.ToString()))
            {
                using (AMS_DMEntities entities = new AMS_DMEntities(conn))
                {
                    Console.WriteLine("connection Ok.");

                    Team team = new Team();
                    team.Name = name;
                    team.Email = email;
                    team.IsExclusive = isExclusive;
                    team.IsActive = isActive;

                    entities.AddToTeams(team);
                    entities.SaveChanges();
                }
            }
        }
开发者ID:Letractively,项目名称:henoch,代码行数:25,代码来源:Repository.cs


示例11: TestEntities

 public TestEntities(EntityConnection connection)
     : base(connection, ContainerName)
 {
     this.ContextOptions.LazyLoadingEnabled = true;
     // 不使用代理类.
     this.ContextOptions.ProxyCreationEnabled = false;
 }
开发者ID:mahuidong,项目名称:my-csharp-sample,代码行数:7,代码来源:TestModel.Context.cs


示例12: RunESQLExample

        public static void RunESQLExample()
        {
            System.Console.WriteLine("\nUsing Entity SQL");

            var esqlQuery = @"SELECT order.SalesOrderID, order.OrderDate, order.DueDate, order.ShipDate FROM AdventureWorksEntities.SalesOrderHeaders AS order where order.SalesOrderID = 43661";

            using (var conn = new EntityConnection("name=AdventureWorksEntities"))
            {
                conn.Open();

                // Create an EntityCommand.
                using (EntityCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = esqlQuery;

                    // Execute the command.
                    using (EntityDataReader rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        // Start reading results.
                        while (rdr.Read())
                        {
                            System.Console.WriteLine("\nSalesOrderID: {0} \nOrderDate: {1} \nDueDate: {2} \nShipDate: {3}", rdr[0], rdr[1], rdr[2], rdr[3]);
                        }
                    }
                }
                conn.Close();
            }
        }
开发者ID:richardrflores,项目名称:efsamples,代码行数:28,代码来源:Queries.cs


示例13: FunWithEntityDataReader

        private static void FunWithEntityDataReader()
        {
            // Make a connection object, based on our *.config file.
            using (EntityConnection cn = new EntityConnection("name=AutoLotEntities"))
            {
                cn.Open();

                // Now build an Entity SQL query.
                string query = "SELECT VALUE car FROM AutoLotEntities.Cars AS car";

                // Create a command object.
                using (EntityCommand cmd = cn.CreateCommand())
                {
                    cmd.CommandText = query;

                    // Finally, get the data reader and process records.
                    using (EntityDataReader dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        while (dr.Read())
                        {
                            Console.WriteLine("***** RECORD *****");
                            Console.WriteLine("ID: {0}", dr["CarID"]);
                            Console.WriteLine("Make: {0}", dr["Make"]);
                            Console.WriteLine("Color: {0}", dr["Color"]);
                            Console.WriteLine("Pet Name: {0}", dr["CarNickname"]);
                            Console.WriteLine();
                        }
                    }
                }
            }
        }
开发者ID:usedflax,项目名称:flaxbox,代码行数:31,代码来源:Program.cs


示例14: EntityTransaction

        internal EntityTransaction(EntityConnection connection, DbTransaction storeTransaction)
        {
            //Contract.Requires(connection != null);
            //Contract.Requires(storeTransaction != null);

            _connection = connection;
            _storeTransaction = storeTransaction;
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:8,代码来源:EntityTransaction.cs


示例15: Test

 public void Test()
 {
     var connection = new EntityConnection(@"metadata=res://*/ProductCatalog.csdl|res://*/ProductCatalog.ssdl|res://*/ProductCatalog.msl;provider=System.Data.SqlClient;provider connection string='Data Source=sr01.lutecia.ge\SQLEXPRESS,1433;Initial Catalog=ProductCatalog;User ID=sa;Password=tatu;MultipleActiveResultSets=True';");
     using (var context = new ProductCatalogContainer(connection))
     {
         Console.WriteLine(context.ProductDetailViewModels.FirstOrDefault());
     }
 }
开发者ID:Antares007,项目名称:InRetail,代码行数:8,代码来源:TestFixture.cs


示例16: EntityTransaction

        /// <summary>
        /// Constructs the EntityTransaction object with an associated connection and the underlying store transaction
        /// </summary>
        /// <param name="connection">The EntityConnetion object owning this transaction</param>
        /// <param name="storeTransaction">The underlying transaction object</param>
        internal EntityTransaction(EntityConnection connection, DbTransaction storeTransaction)
            : base()
        {
            Debug.Assert(connection != null && storeTransaction != null);

            this._connection = connection;
            this._storeTransaction = storeTransaction;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:13,代码来源:EntityTransaction.cs


示例17: SetConnection

        public static void SetConnection(String conn)
        {
            var cb = new EntityConnectionStringBuilder();
            cb.Provider = "System.Data.SqlClient";
            cb.ProviderConnectionString = conn;
            cb.Metadata = "res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl";

            _connrction = new EntityConnection(cb.ConnectionString);
        }
开发者ID:goddenis,项目名称:KruDocTracker,代码行数:9,代码来源:ContextHelper.cs


示例18: SaveMessage

 public void SaveMessage(Message message)
 {
     using (EntityConnection connection = new EntityConnection("name=CoreContainer"))
     {
         _core = new CoreContainer(connection);
         _core.Messages.AddObject(message);
         _core.SaveChanges();
     }
 }
开发者ID:jimgaryphoenix,项目名称:Sierra12,代码行数:9,代码来源:MessageRepository.cs


示例19: CreateTableAndPopulateData

 public static EntityConnection CreateTableAndPopulateData()
 {
     // clear the old connection
     entityConnection = null;
     EntityConnection.Open();
     CreateTable((SqlConnection)EntityConnection.StoreConnection);
     Populate(new CustomObjectContext());
     return EntityConnection;
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:9,代码来源:PopulateData.cs


示例20: AlcionaDataBaseConnection

        private AlcionaDataBaseConnection()
        {
            EntityConnection connection = new EntityConnection();
            string connectionString = ConfigurationManager.ConnectionStrings["AlcionaEntities"].ConnectionString;
            connection.ConnectionString = connectionString;
            connection.Open();
            _context = new AlcionaEntities(connection, false);
            ((IObjectContextAdapter)_context).ObjectContext.CommandTimeout = 3600;

        }
开发者ID:molec1,项目名称:MySPM_NewParsers,代码行数:10,代码来源:AlcionaDataBaseConnection.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# EntityClient.EntityConnectionStringBuilder类代码示例发布时间:2022-05-26
下一篇:
C# ArubaModel.ArubaContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap