This is a migrated thread and some comments may be shown as answers.

QDSCV using query name instead of query

1 Answer 32 Views
DomainDataSource
This is a migrated thread and some comments may be shown as answers.
Colin Cowie
Top achievements
Rank 1
Colin Cowie asked on 19 Apr 2011, 12:45 PM
Is there any way of using the QueryableDomainServiceCollectionView (for an MVVM implementation), and assigning the query using the query name rather than the query itself?  We're trying to implement a generic lookup dialog that will be passed a number of parameters, including the query name, and parameters for the query, and which will then display a grid with the returned data from the query.

I've already tested out converting our DomainDataSource driven maintenance and enquiry routines to using the QueryableDomainServiceCollectionView, which works fine, but each of those is being assigned a specific query from our context. 

I believe I could use reflection to find the query I'm interested in, and have already tried this partially, using:

MyContext.GetType().GetMethod("GetVehiclesForLookupQuery");

But I'm not sure where to go from here, to assign the EntityQuery<Vehicle> variable that I require to initiialise the QueryableDomainServiceCollectionView with.

Any assistance you could give would be great.

Regards,

Colin.

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 19 Apr 2011, 01:06 PM
Hello Colin Cowie,

You are correct. You have to pass in the actual query and can't simply pass its name as a string. You can find it with reflection -- that's what we do as well. You also need to know the entity type, i.e. Vehicle. 

Once you have the EntityQuery instance (i.e. the method on the domain context) and the entity type you can create a generic QDSCV with Activator.CreateInstance. Something like this:

var genericType = typeof(QueryableDomainServiceCollectionView<>)
.MakeGenericType(new System.Type[] { <<the entity type here>> });

var view =
(QueryableDomainServiceCollectionViewBase)Activator.CreateInstance(genericType
, this.DomainContext
, this.EntityQuery);


This is what RadDomainDataSource does internally when it constructs its QDSCV. If you have the source code all of this can be found in the RadDomainDataSource.EntityQuery.cs file for your reference.

Let me know if there are problems.

Best wishes,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
DomainDataSource
Asked by
Colin Cowie
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or