【发布时间】:2017-10-24 19:34:23
【问题描述】:
使用 GET API 方法,我需要使用 Entity Framework 获取表的所有记录的计数。该方法接收一个表名,并以此获取程序集并获取所有记录。但结果是一个 JSON,我还没有找到如何计算这个数。
这是我的代码:
try
{
Type t = Type.GetType("Iwg.Transverse.Business." + tableName + "Manager, Iwg.Transverse.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
MethodInfo method = t.GetMethod("GetAll", Type.EmptyTypes);
var executionMethod = method.Invoke(Activator.CreateInstance(t), null);
JsonResult<object> json = this.Json(executionMethod);
//This line does not work.
//return this.Json(json .Count + 1);
}
catch (Exception e)
{
return this.Json("Error getting the table " + tableName + "\nError " + e.Message);
}
【问题讨论】:
标签: c# json entity-framework json.net system.reflection