本文整理汇总了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();
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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"]);
}
}
}
}
}