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


C# EntityConnection.Close方法代码示例

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


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

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

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

示例3: GetEntityConnection

        /// <summary>
        /// Gets the DB connection
        /// connection parameters are decrypted
        /// </summary>
        /// <returns>An Entity (Framework) connection</returns>
        public static EntityConnection GetEntityConnection(string serverURI)
        {
            EntityConnection ans = null;
            EntityConnection conn = null;
            try
            {
                // Initialize the EntityConnectionStringBuilder.
                EntityConnectionStringBuilder entityBuilder =
                    new EntityConnectionStringBuilder();

                // Set the provider name.
                entityBuilder.Provider = "MySql.Data.MySqlClient";

                // Set the provider-specific connection string.
                entityBuilder.ProviderConnectionString = GetSqlBuilder(serverURI).ToString();

                // Set the Metadata location.
                entityBuilder.Metadata = @"res://*/Entities.BourseEntities.csdl|res://*/Entities.BourseEntities.ssdl|res://*/Entities.BourseEntities.msl";
                string st = entityBuilder.ToString();

                conn = new EntityConnection(entityBuilder.ToString());

                conn.Open();

                // Just testing the connection.
                conn.Close();

                // CA2000 prevention
                ans = conn;
                conn = null;

                return ans;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
开发者ID:Vinzz,项目名称:BourseVetements,代码行数:50,代码来源:DBConnection.cs

示例4: ExecuteESqlQuery

 internal static void ExecuteESqlQuery(string cxString, string query)
 {
     EntityConnection connection = new EntityConnection(cxString);
     EntityCommand command = new EntityCommand(query, connection);
     connection.Open();
     try
     {
         command.ExecuteReader(CommandBehavior.SequentialAccess).Dump<EntityDataReader>();
     }
     finally
     {
         connection.Close();
     }
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:14,代码来源:EntityFrameworkHelper.cs

示例5: GetGenres

        public Genre[] GetGenres()
        {
            Genre[] genres = null;

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("SELECT g.genreid, g.genre1 FROM tunesEntities.titel AS a");
            stringBuilder.Append(" INNER JOIN tunesEntities.genre AS g ON a.genreid = g.genreid");
            stringBuilder.Append(" INNER JOIN tunesEntities.lieder AS t ON a.TitelID = t.TitelID");
            stringBuilder.Append(" WHERE t.Liedpfad IS NOT NULL");
            stringBuilder.Append(" GROUP BY g.genreid, g.genre1");
            stringBuilder.Append(" ORDER BY g.genre1");

            using (System.Data.EntityClient.EntityConnection entityConnection =
                    new System.Data.EntityClient.EntityConnection(this.ConnectionString))
            {
                try
                {
                    entityConnection.Open();
                    using (EntityCommand entityCommand = entityConnection.CreateCommand())
                    {
                        List<Genre> genreCollection = null;
                        entityCommand.CommandText = stringBuilder.ToString();
                        // Execute the command.
                        using (EntityDataReader dataReader =
                            entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                        {
                            // Start reading results.
                            while (dataReader.Read())
                            {
                                IDataReader dataR = dataReader;
                                if (genreCollection == null)
                                {
                                    genreCollection = new List<Genre>();
                                }
                                Genre genre = new Genre
                                {
                                    Id = dataReader.GetInt32("genreid", false, 0),
                                    Name = dataReader.GetString("genre1", false, string.Empty)
                                };
                                genreCollection.Add(genre);
                            }
                        }
                        if (genreCollection != null)
                        {
                            genres = genreCollection.ToArray();
                        }
                    }
                }
                finally
                {
                    entityConnection.Close();
                }
            }
            return genres;
        }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:55,代码来源:TunesBusinessObject.cs

示例6: GetTracksByFilters

        public ICollection<Track> GetTracksByFilters(Filter filter)
        {
            Collection<Track> tracks = null;
            if (filter != null)
            {
                //filter.Value = "17,25,5,14";
                var names = new int[] { 17, 25, 5, 14 };

                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT t.LiedID, t.Track, t.Lied ,t.Dauer");
                stringBuilder.Append(" FROM tunesEntities.lieder AS t");
                stringBuilder.Append(" INNER JOIN tunesEntities.titel AS a ON t.TitelID = a.TitelID");
                stringBuilder.Append(" WHERE t.Liedpfad IS NOT NULL");
                //stringBuilder.Append(" AND a.genreid IN (17,25,5,14)");
                
                switch (filter.Mode)
                {
                    case FilterMode.Genre:
                        stringBuilder.Append(" AND a.genreid IN {" + filter.Value + "}");
                        //stringBuilder.Append(" AND a.genreid IN (@filterValue)");
                        break;
                    case FilterMode.Year:
                        break;
                    default:
                        break;
                }

                string sql = stringBuilder.ToString();
                using (System.Data.EntityClient.EntityConnection entityConnection =
                   new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            //EntityParameter filterValue = new EntityParameter();
                            //filterValue.ParameterName = "filterValue";
                            //filterValue.Value = filter.Value;
                            //entityCommand.Parameters.Add(filterValue);
                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                // Start reading results.
                                while (dataReader.Read())
                                {
                                    if (tracks == null)
                                    {
                                        tracks = new Collection<Track>();
                                    }
                                    Track track = new Track
                                    {
                                        Id = dataReader.GetInt32("LiedID", false, 0)
                                    };
                                    tracks.Add(track);
                                }
                            }
                        }
                    }
                    finally
                    {
                        entityConnection.Close();
                    }
                }

            }
            return tracks;
        }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:69,代码来源:TunesBusinessObject.cs

示例7: GetTrackById

        public Track GetTrackById(int trackId)
        {
            Track track = null;
            string audioDirectory = this.AudioDirectory;
            if (string.IsNullOrEmpty(audioDirectory) == false)
            {
                StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("SELECT t.LiedID, t.Track, t.Lied ,t.Dauer, t.Liedpfad, t.guid, a.TitelID, a.Titel1, a.Guid as AlbumId, i.Interpret FROM tunesEntities.lieder AS t");
                stringBuilder.Append(" JOIN tunesEntities.titel AS a ON a.TitelID = t.TitelID");
                stringBuilder.Append(" JOIN tunesEntities.interpreten AS i ON a.InterpretID = i.InterpretID");
                stringBuilder.Append(" WHERE t.LiedId = @trackid");

                string sql = stringBuilder.ToString();
                using (System.Data.EntityClient.EntityConnection entityConnection =
                        new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            EntityParameter trackIdParam = new EntityParameter();
                            trackIdParam.ParameterName = "trackid";
                            trackIdParam.Value = trackId;
                            entityCommand.Parameters.Add(trackIdParam);

                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                if (dataReader.Read() == true)
                                {
									track = new Track
									{
										Id = dataReader.GetInt32("LiedID", false, 0),
										TrackNumber = dataReader.GetInt32("Track", false, 0),
										Name = dataReader.GetString("Lied", false, string.Empty),
										Duration = dataReader.GetTimeSpan("Dauer", true, TimeSpan.MinValue),
										Guid = dataReader.GetGuid("guid", false, Guid.Empty),
										Album = new Album
										{
											Id = dataReader.GetInt32("TitelID", false, 0),
											Title = dataReader.GetString("Titel1", false, string.Empty),
											AlbumId = dataReader.GetGuid("AlbumId", false, Guid.Empty),
											Artist = new Artist
											{
												Name = dataReader.GetString("Interpret", false, string.Empty)
											}
										}
									};
                                }
                            }
                        }
                    }
                    finally
                    {
                        entityConnection.Close();
                    }
                }
            }
            return track;
        }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:62,代码来源:TunesBusinessObject.cs

示例8: GetAudioFileNameByGuid

        public string GetAudioFileNameByGuid(Guid guid)
        {
            string fileName = null;
            string audioDirectory = this.AudioDirectory;
            if (string.IsNullOrEmpty(audioDirectory) == false && guid != null && guid != Guid.Empty)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT t.Liedpfad FROM tunesEntities.lieder AS t");
                stringBuilder.Append(" WHERE t.guid = @guid");

                string sql = stringBuilder.ToString();
                using (System.Data.EntityClient.EntityConnection entityConnection =
                        new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            EntityParameter guidParam = new EntityParameter();
                            guidParam.ParameterName = "guid";
                            guidParam.Value = guid.ToString();
                            entityCommand.Parameters.Add(guidParam);

                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                if (dataReader.Read() == true)
                                {
                                    fileName = GetTrackFilePath(dataReader, audioDirectory);
                                }
                            }
                        }
                    }
                    finally
                    {
                        entityConnection.Close();
                    }
                }
            }
            return fileName;
        }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:43,代码来源:TunesBusinessObject.cs

示例9: GetImage

		public CoverImage GetImage(Guid imageId, bool asThumbnail = false)
		{
			CoverImage image = null;

			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("SELECT a.{0}, a.PictureFormat, a.ErstellDatum, a.MutationDatum");
			stringBuilder.Append(" FROM tunesEntities.titel AS a");
			stringBuilder.Append(" WHERE a.guid = @imageId");

			string field = asThumbnail ? "thumbnail" : "cover";
			string sql = string.Format(CultureInfo.InvariantCulture, stringBuilder.ToString(), field);

			using (System.Data.EntityClient.EntityConnection entityConnection =
					new System.Data.EntityClient.EntityConnection(this.ConnectionString))
			{
				try
				{
					entityConnection.Open();
					using (EntityCommand entityCommand = entityConnection.CreateCommand())
					{
						EntityParameter id = new EntityParameter();
						id.ParameterName = "imageId";
						id.Value = imageId.ToString();
						entityCommand.Parameters.Add(id);
						entityCommand.CommandText = sql;
						using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
						{
							if (dataReader.Read())
							{
								image = new CoverImage
								{
									Cover = dataReader.GetBytes(field, true, null),
									Extension = dataReader.GetString("PictureFormat", true,String.Empty),
									ModifiedSince = dataReader.GetDateTime("MutationDatum", true, DateTime.MinValue)
								};
							}
						}
					}
				}
				finally
				{
					entityConnection.Close();
				}
			}
			return image;
		}
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:46,代码来源:TunesBusinessObject.cs

示例10: GetPlaylistsByUserName

        public Playlist[] GetPlaylistsByUserName(string userName, int limit)
        {
            Playlist[] playlists = null;
            if (!string.IsNullOrEmpty(userName))
            {
                bool hasLimit = false;
                if (limit > 0)
                {
                    hasLimit = true;
                }

                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT p.ListId, p.ListName, p.User, p.guid FROM tunesEntities.playlist AS p");
                stringBuilder.Append(" WHERE p.User = @userName");
                stringBuilder.Append(" ORDER BY p.ListName");
                if (hasLimit)
                {
                    stringBuilder.Append(" LIMIT @limit ");
                }
                string sql = stringBuilder.ToString();

                using (System.Data.EntityClient.EntityConnection entityConnection =
                    new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            EntityParameter user = new EntityParameter();
                            user.ParameterName = "userName";
                            user.Value = userName;
                            entityCommand.Parameters.Add(user);

                            EntityParameter limitParam = new EntityParameter();
                            limitParam.ParameterName = "limit";
                            limitParam.Value = limit;
                            entityCommand.Parameters.Add(limitParam);

                            List<Playlist> playlistCollection = null;
                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                // Start reading results.
                                while (dataReader.Read())
                                {
                                    if (playlistCollection == null)
                                    {
                                        playlistCollection = new List<Playlist>();
                                    }

                                    Playlist playlist = new Playlist
                                    {
                                        Id = dataReader.GetInt32("ListId", false, 0),
                                        Name = dataReader.GetString("ListName", false, string.Empty),
                                        UserName = dataReader.GetString("User", false, string.Empty),
                                        Guid = dataReader.GetGuid("guid", true, Guid.Empty)
                                    };
                                    playlistCollection.Add(playlist);
                                }
                            }
                            if (playlistCollection != null)
                            {
                                playlists = playlistCollection.ToArray();

                            }
                        }
                    }
                    finally
                    {
                        entityConnection.Close();
                    }
                }
            }
            return playlists;
        }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:77,代码来源:TunesBusinessObject.cs

示例11: GetAlbums

        public Album[] GetAlbums(Query query)
        {
            Album[] albums = null;
            if (query == null)
            {
                query = new Query
                {
                    PageIndex = 0,
                    PageSize = 1
                };
            }

            query.PageSize = query.PageSize == 0 ? 1 : query.PageSize;

            StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("SELECT i.InterpretID, i.Interpret, i.Interpret_Lang ,a.TitelID, a.Titel1, a.Guid as AlbumId FROM tunesEntities.titel AS a");
            stringBuilder.Append(" INNER JOIN tunesEntities.interpreten AS i ON a.InterpretID = i.InterpretID");
            stringBuilder.Append(" INNER JOIN tunesEntities.lieder AS t ON a.TitelID = t.TitelID");
            stringBuilder.Append(" WHERE t.Liedpfad IS NOT NULL");
			stringBuilder.Append(" GROUP BY i.InterpretID, i.Interpret, i.Interpret_Lang ,a.TitelID, a.Titel1, a.Guid");
            if (query.SortByCondition != null && query.SortByCondition.Id == 1)
            {
                stringBuilder.Append(" ORDER BY a.Titel1");
            }
            else
            {
                stringBuilder.Append(" ORDER BY i.Interpret, a.Titel1");
            }
            stringBuilder.Append(" SKIP @skip LIMIT @limit ");

            string sql = stringBuilder.ToString();

            using (System.Data.EntityClient.EntityConnection entityConnection =
                new System.Data.EntityClient.EntityConnection(this.ConnectionString))
            {
                try
                {
                    entityConnection.Open();
                    using (EntityCommand entityCommand = entityConnection.CreateCommand())
                    {
                        EntityParameter skip = new EntityParameter();
                        skip.ParameterName = "skip";
                        skip.Value = query.PageIndex;
                        entityCommand.Parameters.Add(skip);

                        EntityParameter limit = new EntityParameter();
                        limit.ParameterName = "limit";
                        limit.Value = query.PageSize;
                        entityCommand.Parameters.Add(limit);

                        List<Album> albumCollection = null;
                        entityCommand.CommandText = sql;
                        // Execute the command.
                        using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                        {
                            // Start reading results.
                            while (dataReader.Read())
                            {
                                if (albumCollection == null)
                                {
                                    albumCollection = new List<Album>();
                                }
                                Album album = new Album
                                {
                                    Artist = new Artist
                                    {
                                        Id = dataReader.GetInt32("InterpretID", false, 0),
                                        Name = dataReader.GetString("Interpret", false, string.Empty),
                                        SortName = dataReader.GetString("Interpret_Lang", true, string.Empty)
                                    },
                                    Id = dataReader.GetInt32("TitelID", false, 0),
                                    Title = dataReader.GetString("Titel1", false, string.Empty),
									AlbumId = dataReader.GetGuid("AlbumId", false, Guid.Empty)

                                };
                                albumCollection.Add(album);
                            }
                        }
                        if (albumCollection != null)
                        {
                            albums = albumCollection.ToArray();
                        }
                    }
                }
                finally
                {
                    entityConnection.Close();
                }
            }
            return albums;
        }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:91,代码来源:TunesBusinessObject.cs

示例12: GetNumberOfPlayableAlbums

        public int GetNumberOfPlayableAlbums()
        {
            int iNumberofAlbums = -1;

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("SELECT COUNT(DISTINCT a.TitelID) FROM tunesEntities.titel AS a");
            stringBuilder.Append(" INNER JOIN tunesEntities.lieder AS t ON a.TitelID = t.TitelID");
            stringBuilder.Append(" WHERE t.Liedpfad IS NOT NULL");

            string sql = stringBuilder.ToString();
            using (System.Data.EntityClient.EntityConnection entityConnection =
                    new System.Data.EntityClient.EntityConnection(this.ConnectionString))
            {
                try
                {
                    entityConnection.Open();
                    using (EntityCommand entityCommand = entityConnection.CreateCommand())
                    {
                        entityCommand.CommandText = sql;
                        object obj = entityCommand.ExecuteScalar();
                        if (obj is int)
                        {
                            iNumberofAlbums = (int)obj;
                        }
                    }
                }
                finally
                {
                    entityConnection.Close();
                }
            }
            return iNumberofAlbums;
        }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:33,代码来源:TunesBusinessObject.cs

示例13: GetPlaylistByIdWithNumberOfEntries

        public Playlist GetPlaylistByIdWithNumberOfEntries(int playlistId, string userName)
        {
            Playlist playlist = null;
            if (string.IsNullOrEmpty(userName) == false)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT p.ListId, p.ListName, p.guid, COUNT(pe.PlaylistId) as Number ");
				stringBuilder.Append(" FROM tunesEntities.playlist AS p");
                stringBuilder.Append(" LEFT JOIN tunesEntities.playlistentries AS pe ON p.ListId = pe.PlaylistId");
                stringBuilder.Append(" WHERE p.ListId = @playlistId");
                stringBuilder.Append(" AND p.User = @userName");
				stringBuilder.Append(" GROUP BY p.listid, p.ListName, p.guid");

                string sql = stringBuilder.ToString();
                using (System.Data.EntityClient.EntityConnection entityConnection =
                        new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            EntityParameter id = new EntityParameter();
                            id.ParameterName = "playlistId";
                            id.Value = playlistId;
                            entityCommand.Parameters.Add(id);

                            EntityParameter user = new EntityParameter();
                            user.ParameterName = "userName";
                            user.Value = userName;
                            entityCommand.Parameters.Add(user);

                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                if (dataReader.Read() == true)
                                {
                                    playlist = new Playlist
                                    {
                                        Id = dataReader.GetInt32("ListId", false, 0),
                                        Name = dataReader.GetString("ListName", false, string.Empty),
										Guid = dataReader.GetGuid("guid", false, Guid.Empty),
										NumberEntries = dataReader.GetInt32("Number", false, 0)
                                    };
                                }
                            }
                        }
                    }
						catch(Exception ex)
					{
					}
                    finally
                    {
                        entityConnection.Close();
                    }
                }
            }
            return playlist;
        }
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:60,代码来源:TunesBusinessObject.cs

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

示例15: ejemploentity

 private void ejemploentity()
 {
     using (EntityConnection conn = new EntityConnection("name=travelEntitiesGeneral"))
     {
         conn.Open();
         EntityCommand cmd = conn.CreateCommand();
         cmd.CommandText = @"select c.BlogID from travelEntitiesGeneral.Blogs as c where c.BlogPosts.Count > 0";
         EntityDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
         while (reader.Read())
         {
             Console.WriteLine("BlogID = {0}", reader["BlogID"]);
         }
         conn.Close();
     }
 }
开发者ID:borisgr04,项目名称:ByA_Sircc,代码行数:15,代码来源:CGTraslados.cs


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