none
EntityDataSource return entities as a list of objects RRS feed

  • Question

  •  

    Typicaly I bind to EDS using databound controls but now (and I believe even more so in the future) I need to programatically retrieve those entities that EDS returns, specifically after the Where property has been set.

     

    I have to be able to do that on-demand so not in events like RowDatabound etc.

     

    I think extension method will be needed once again but don't know how to write it.

     

    Also If MS is reading this I would recommend posting some tutorials on this subject because it seems there is not enough documentation - most of it deals with simple databinding which is pretty straightforward.

    Wednesday, October 22, 2008 1:02 PM

Answers

  • Hi,

    The EntityDataSource is a wrapper around object of the Entity Framework so that you can use it easily in the markup pages. However, when dealing programatically with queries, you should go back to the basic objects themselves: either use a Linq query or an ObjectQuery. Here is an example:

     string query = "select value obj from Entities.Class as obj " +
                           
    "where obj.Property = @Value";

           
    ObjectQuery<Class> oQuery = new ObjectQuery<Class>(query, EntityContext.Instance);
            oQuery
    .Parameters.Add(new ObjectParameter("Value", someVariable));

    You'll need to replace the 'Entities' with your own Entity Model name. You can then use the oQuery to get the records as you wish.

    Even easier is to use the entity object directly: EntityModel.YourObjectSet.Where( it => it.Blah = this.Bleh ).

    Alain-Daniel
    Wednesday, October 22, 2008 2:31 PM

All replies

  • Hi,

    The EntityDataSource is a wrapper around object of the Entity Framework so that you can use it easily in the markup pages. However, when dealing programatically with queries, you should go back to the basic objects themselves: either use a Linq query or an ObjectQuery. Here is an example:

     string query = "select value obj from Entities.Class as obj " +
                           
    "where obj.Property = @Value";

           
    ObjectQuery<Class> oQuery = new ObjectQuery<Class>(query, EntityContext.Instance);
            oQuery
    .Parameters.Add(new ObjectParameter("Value", someVariable));

    You'll need to replace the 'Entities' with your own Entity Model name. You can then use the oQuery to get the records as you wish.

    Even easier is to use the entity object directly: EntityModel.YourObjectSet.Where( it => it.Blah = this.Bleh ).

    Alain-Daniel
    Wednesday, October 22, 2008 2:31 PM
  • Thank you, I was aware of that option but thought it could be some way to expose it from EntityDataSource. Guess this will have to do it.

     

    Wednesday, October 22, 2008 3:22 PM
  •  

    I dont understand the problem. Can you give exact details on what you want?
    Wednesday, October 22, 2008 5:03 PM
  • I just thought if there was a way to expose entities that EDS returns to databound controls as a property or a method. 

    Wednesday, October 22, 2008 9:13 PM
  • This is an old post, but I thought I'd chime in. I too would like to access entities selected by the EntityDataSource for the purpose of calculating totals. I understand that this is impossible, however, because the EntityDataSource uses server-side paging, so it doesn't return all the entities anyway.
    Zachary
    Thursday, February 24, 2011 10:35 PM