views:

199

answers:

1

I am trying to create a generic search form to use in an EF app. I want to be ably to specify the entity to query at runtime below is a simplified version of the code.

cx is the contect object, valuelists is the entity in question.

1: Dim q As String = "select c from intactentities.valuelists as c"
2: Dim x = cx.CreateQuery(Of ValueLists)(q)
3: TextBox1.Text = x.Count

This works but I need to remove the hardcoded reference to valuelists in line 3. I expect I am overlooking something simple can anyone suggest a simple solution?

Thanks Tony

A: 

You can just create query of Object:

Dim x = cx.CreateQuery(Of Object)(q)

It will work with every type of entity.

LukLed
The problem with declaring it as object is that it looses something in the translation and I get errors when trying to bind it to a datagrid, or access the member properties. Thanks for the suggestion tho.T
Tony Heflin
@Tony Heflin: I'll have to look into it. It seemed working for me.
LukLed