How do I call the Count method on an Entity Framework Context by using Reflection?
I'm trying to get count of records of each table by using the following code. But it doesn't work at all. GetMethod("Count") returns always null. I might do really stupid thing though, I don't know what to do.
var list = new List<Tabl开发者_JAVA技巧eInfoContainer>
{
new TableInfoContainer{ObjectSetPropertyName="table1"},
new TableInfoContainer{ObjectSetPropertyName="table2"},
new TableInfoContainer{ObjectSetPropertyName="table3"},
};
using (var context = new DBEntities())
{
list.ForEach(x =>{
var property = context.GetType().GetProperty(x.ObjectSetPropertyName);
x.RecordCount = (int)typeof(IQueryable).GetMethod("Count").Invoke(property, null);
});
}
Aany help would be appreciated!
Thanks, yokyo
精彩评论