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


C# EntityConnection.CreateCommand方法代码示例

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


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

示例1: 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,项目名称:ByASircc4v2016,代码行数:14,代码来源:CGTraslados.cs

示例2: Main

 static void Main(string[] args)
 {
     string city = "London";
     using (EntityConnection cn = new EntityConnection("Name=Entities"))
     {
         cn.Open();
         EntityCommand cmd = cn.CreateCommand();
         cmd.CommandText = @"SELECT VALUE c FROM Entities.Customers AS c WHERE
              c.Address.City = @city";
         cmd.Parameters.AddWithValue("city", city);
         DbDataReader rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
         while (rdr.Read())
             Console.WriteLine(rdr["CompanyName"].ToString());
         rdr.Close();
     }
 }
开发者ID:eliver,项目名称:GitNugetTest,代码行数:16,代码来源:Program.cs

示例3: When_Same_Primary_Key_Name_Is_Used_For_Two_Tables_Correct_Number_Of_MetaData_Rows_Is_Returned

        public void When_Same_Primary_Key_Name_Is_Used_For_Two_Tables_Correct_Number_Of_MetaData_Rows_Is_Returned()
        {
            this.CreateIfNotExists();
            var workspace = CreateMetadataWorkspace();            
            var connection = new EntityConnection(workspace, new SqlCeConnection(dbConnectionString));
            connection.Open();
            var command = connection.CreateCommand();
            command.CommandText = TableDetailSql;
            var rowCount = 0;

            using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess))
            {
                while (reader.Read())
                {
                    rowCount++;
                }
            }

            Assert.Equal(4, rowCount);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:20,代码来源:CodePlex2197.cs

示例4: EntitySQL

        public ActionResult EntitySQL(int id = 0)
        {
            string esqlQuery = @"SELECT VALUE customers FROM AdventureWorksEntities.Customers AS customers  WHERE customers.CustomerID == @id";

            var customers = new List<Customer2>();
            using(var conn = new EntityConnection("name=AdventureWorksEntities"))
            {
                conn.Open();

                using(var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = esqlQuery;
                    var param = new EntityParameter {
                        ParameterName = "id",
                        Value = id
                    };
                    cmd.Parameters.Add(param);

                    using(var reader = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                    {
                        while (reader.Read())
                        {
                            var customer = new Customer2
                            {
                                CustomerID = int.Parse(reader["CustomerID"].ToString()),
                                CustomerName = reader["FirstName"] + " " + reader["MiddleName"] + " " + reader["LastName"]
                            };

                            customers.Add(customer);
                        }
                    }
                }

                conn.Close();
            }

            return View(customers);
        }
开发者ID:Karolinebryn,项目名称:SampleCodeCertification70-487,代码行数:38,代码来源:DbContextController.cs

示例5: FunWithEntityDataReader

        private static void FunWithEntityDataReader() {
            using (EntityConnection cn = new EntityConnection("name=AutoLotEntities")) {
                cn.Open();
                string queryString = "SELECT VALUE car from AutoLotEntities.Cars as car WHERE car.Color='Black'";
                using (EntityCommand cmd = cn.CreateCommand()) {
                    cmd.CommandText = queryString;

                    using (EntityDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)) {
                        while (dr.Read()) {
                            Console.WriteLine(dr["CarID"]);
                        }
                    }
                }
            }                
        }
开发者ID:Geronimobile,项目名称:DotNetExamIntro,代码行数:15,代码来源:Program.cs


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