Entity framework createquery question
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
You can just create query of Object:
Dim x = cx.CreateQuery(Of Object)(q)
It will work with every type of entity.
精彩评论