开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜