4
ジェネリッククラスTからジェネリッククエリを作成したいと思います。リフレクションなどを使用する方法がありますか?リフレクションを使用して一般的なエンティティから(名前で)プロパティにアクセスできますか?
public class DAO<T>
where T : class
{
protected ObjectSet<T> Entities
{
get
{
return myContextThatIsInSomewhere.CreateObjectSet<T>();
}
}
public IList<T> SelectBy(object fields)
{
if (fields == null)
{
throw new ArgumentNullException("fields");
}
var query = from e in this.Entities
select e;
foreach (var field in fields.GetType().GetFields())
{
query = from e in this.Entities
// Do something like that:
where e.(field.Name) == field.GetValue()
select e;
}
return query.ToList();
}
}
ありがとう、Jason! –