【发布时间】:2019-12-01 14:19:22
【问题描述】:
这里是实体框架/MVC 新手。 编写我的第一个 EF 应用程序 (api)。到目前为止一切顺利,我可以从数据库中检索行,但现在我被一个我无法解决的问题阻止了。 我不知道如何操作返回的值。我检索了一个包含 5 列的结果集,我想在将单个值以 JSON 字符串返回给调用应用程序之前对其进行加密。谁能指出我在代码中实现这一目标的示例?模型?存储库?我迷路了。
namespace app.Models
{
public class ParameterSet
{
public int id { get; set; }
public string DbServerInstance { get; set; }
public string DbServerUser { get; set; }
public string DbServerPassword { get; set; }
public string DbServerDatabase { get; set; }
}
}
连接上下文
namespace app.Repositories
{
public class DbconnectionContext : DbContext
{
public DbconnectionContext() : base("MobileAppsConnection")
{
Database.SetInitializer<DbconnectionContext>(null);
}
public DbSet<ParameterSet> ParameterSet { get; set; }
}
}
界面
namespace app.Repositories
{
interface IParameterSets
{
IEnumerable<ParameterSet> ListofParameterSet();
}
}
存储库
namespace MobileAppsService.Repositories
{
public class ParameterSets : IParameterSets
{
public IEnumerable<ParameterSet> ListofParameterSet()
{
using (DbconnectionContext context = new DbconnectionContext())
{
var listofparameters = from parameters in context.ParameterSet
select parameters;
return listofparameters.ToList();
}
}
}
}
值控制器
namespace MobileAppsService.Controllers
{
public class ValuesController : ApiController
{
readonly IParameterSets Iparamset;
public ValuesController()
{
Iparamset = new ParameterSets();
}
// GET api/values
public IEnumerable<ParameterSet> GetAlldata()
{
return Iparamset.ListofParameterSet();
}
}
}
【问题讨论】:
-
格式问题见谅
标签: c# entity-framework asp.net-mvc-4