janosch
2009-09-30 17:38:00 UTC
Hallo,
das Beispiel aus http://msdn.microsoft.com/de-de/library/bb882637.aspx
habe ich wie folgt abgeändert:
Type globObj = ssb.ssbGlobObj.Typ; //enthalten Angaben zum
Type der zur Laufzeit verwendeten Klasse
Dictionary<int, StayReference> dictStRF = qRF.DictSTRF; //
enthält die Objekte vom Typ StayReference und soll abgefragt werden
IQueryable<StayReference> queryableData =
dictStRF.Values.ToList().AsQueryable<StayReference>();
ParameterExpression pe = Expression.Parameter(globObj,
"stayRef");
Expression left = Expression.Property(pe,
globObj.GetProperty("CaseID", typeof(int)));
Expression right = Expression.Constant(13554, typeof
(int));
Expression e1 = Expression.Equal(left, right);
MethodCallExpression whereCallExpression = Expression.Call
(
typeof(Queryable),
"Where",
new Type[] { queryableData.ElementType },
queryableData.Expression,
Expression.Lambda<Func<StayReference, bool>>(e1, new
ParameterExpression[] { pe }));
IQueryable<StayReference> results =
queryableData.Provider.CreateQuery<StayReference>
(whereCallExpression);
foreach (StayReference company in results)
listBox1.Items.Add(company.CaseID.ToString());
Soweit, so gut. Wie schaffe ich es jetzt aber, die Anfrage auf eine
mir vorher unbekannte Klasse zu starten? Also so, dass nicht mehr
überall StayRefence drin steht, sondern ich das erst zur Laufzeit
übergebe?
das Beispiel aus http://msdn.microsoft.com/de-de/library/bb882637.aspx
habe ich wie folgt abgeändert:
Type globObj = ssb.ssbGlobObj.Typ; //enthalten Angaben zum
Type der zur Laufzeit verwendeten Klasse
Dictionary<int, StayReference> dictStRF = qRF.DictSTRF; //
enthält die Objekte vom Typ StayReference und soll abgefragt werden
IQueryable<StayReference> queryableData =
dictStRF.Values.ToList().AsQueryable<StayReference>();
ParameterExpression pe = Expression.Parameter(globObj,
"stayRef");
Expression left = Expression.Property(pe,
globObj.GetProperty("CaseID", typeof(int)));
Expression right = Expression.Constant(13554, typeof
(int));
Expression e1 = Expression.Equal(left, right);
MethodCallExpression whereCallExpression = Expression.Call
(
typeof(Queryable),
"Where",
new Type[] { queryableData.ElementType },
queryableData.Expression,
Expression.Lambda<Func<StayReference, bool>>(e1, new
ParameterExpression[] { pe }));
IQueryable<StayReference> results =
queryableData.Provider.CreateQuery<StayReference>
(whereCallExpression);
foreach (StayReference company in results)
listBox1.Items.Add(company.CaseID.ToString());
Soweit, so gut. Wie schaffe ich es jetzt aber, die Anfrage auf eine
mir vorher unbekannte Klasse zu starten? Also so, dass nicht mehr
überall StayRefence drin steht, sondern ich das erst zur Laufzeit
übergebe?