0

Is there a way to use an entitydatasource that has an arbitrary join as the source for an editable gridview?

I am using entity-framework and linq to sql.

I would like a gridview that is currently editable using the "built in" edit mode and paging to only show items that have an entry in a second table (an order book). There is no relationship between these two tables in SQL or in the EDMX model and I have no access to either.

Gordon Copestake
  • 1,616
  • 4
  • 21
  • 37

1 Answers1

1

Use something like this; It binds a view to a table object using a ID column. Bind to the querycreated event. AND!! make sure you do no have any filtering already applied in the creation of the EntityDataSource. If you do select it.[XYZ] then it returns an anonymous type that cannot be type casted. Note the e.Query.Cast()

 protected void EntityDataSource1_OnQueryCreated(object sender, QueryCreatedEventArgs e)
        {
            var filters = DomainFilters;

            if (filters.Count > 0)
            {
                e.Query = from view in e.Query.Cast<MAPPING_VIEW>()
                          join bo1 in SecurityContext.MAP_TYPE
                              on view.MAP_TYPE_ID equals bo1.MAP_TYPE_ID
                          where filters.Contains(bo1.DOMAIN_ID)
                          orderby view.NAME
                          select view;
            }
            else
            {
                e.Query = from view in e.Query.Cast<MAPPING_VIEW>()
                          orderby view.NAME
                          select view;
            }
        }
Steve Coleman
  • 1,987
  • 2
  • 17
  • 28