有什么方法可以帮助我从Microsoft的表中选择特定的数据吗.AspNetCore.数据同步.EFCore



我正在学习从API到WPF应用程序的数据同步。收到来自的演示https://github.com/Azure/azure-mobile-apps/tree/main/samples.但我遇到了一个问题,表中的所有数据都是在调用中收集的,但我需要使用Id选择特定的数据。尝试了一个查询等,但都没有结果。请引导我谢谢

PatientsController.cs

[Route("tables/Patients")]
public class PatientsController : TableController<Patients>
{
public PatientsController(AppDbContext context)
: base(new EntityTableRepository<Patients>(context))
{
}
}

AppDbContext.cs

public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
public DbSet<Patients> Patients => Set<Patients>();
}

尝试使用以下代码:

public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
public DbSet<Patients> Patients {get;set;}
}

控制器:

[Route("tables/Patients")]
public class PatientsController : TableController<Patients>
{
private readonly AppDbContext _context;
public PatientsController(AppDbContext context)
: base(new EntityTableRepository<Patients>(context))
{
_context=context;
}
public async Task<IActionResult> Index(int id){
var Patients=_context.Patients.FindAsync(id);
return View(Patients);
}
}

如果您只需要按Id获取记录,则使用URLhttps://mysite/tables/myTable/id-无需搜索-它将直接指向您想要的实体。

如果需要限制用户可以看到的内容,则需要实现一个访问控制提供程序(它是IAccessControlProvider的实现(。这提供了三种方法来限制用户可以看到的内容,并进行模型更新,以确保写入操作存储正确的内容。您可以在此处阅读更多信息:https://learn.microsoft.com/en-us/azure/developer/mobile-apps/azure-mobile-apps/howto/server/dotnet-core#configure-访问权限

如果是其他事情,你需要更具体一点。我经常参与azure/azure移动应用程序回购的问题和讨论,所以可以在那里提出问题。

最新更新