为什么Entity Framework中的ExecuteReader需要CommandBehavior.SequentialAccess?

时间:2013-04-10 05:08:30

标签: entity-framework entity-framework-4

我是Entity Framework的新手,并且不理解为什么ExecuteReader需要CommandBehavior.SequentialAccess。以下是我的代码..

 using (var conn = new EntityConnection("name=EFRecipesEntities"))
    {
       Console.WriteLine("Customers...");
       var cmd = conn.CreateCommand();
       conn.Open();
       cmd.CommandText = @"select c.Name, C.Email from
       EFRecipesEntities.Customers as c";
       using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
       {
           while (reader.Read())
           {
              Console.WriteLine("{0}'s email is: {1}",
              reader.GetString(0), reader.GetString(1));
           }
       }
    }

任何帮助..

1 个答案:

答案 0 :(得分:1)

来自http://blogs.msdn.com/b/alexj/archive/2007/11/15/commandbehavior-sequentialaccess.aspx?Redirected=true的微软

在EntityDataReader中,有时候Cell(行和列的交集)实际上也拥有另一个Reader。缓存已读过去的嵌套读者有点棘手。所以至少现在我们不支持非顺序访问。