views:

45

answers:

1

Hello

I have this code:

public IEnumerable<SomeClass> GetAvalibleThingies(DateTime startDate, DateTime endDate, int categoryID)
    {


        if (_entities.Connection.State == System.Data.ConnectionState.Closed)
            _entities.Connection.Open();

        using (EntityCommand c = new EntityCommand("SomeEntities.GetAvalibleThingies", (EntityConnection)this._entities.Connection))
        {
            c.CommandType = System.Data.CommandType.StoredProcedure;

            EntityParameter paramstartDate = new EntityParameter("startDate", System.Data.DbType.DateTime);
            paramstartDate.Direction = System.Data.ParameterDirection.Input;
            paramstartDate.Value = startDate;
            c.Parameters.Add(paramstartDate);

    ........
            var x = c.ExecuteReader();

            return x as IEnumerable<SomeClass>;
        };

But I can't get it to return a list of SomeClass. What's needed to do here? I use the entity framework 3.5sp1 one

/M

+1  A: 

EntityDataReader is a class similar to SqlDataReader and should be handled in the similar way.
Instead of the lines

  var x = c.ExecuteReader();
  return x as IEnumerable; 

should be something like


  List list = new List();
  using(EntityDataReader reader = c.ExecuteReader()) {
    while(reader.Read()) {
      SomeClass item = new SomeClass() {
      };
      list.Add(item);
    }
  }
  return list;
Devart
How do I get the value for each "SomeID" in the reader?
molgan