Asp.Net Boilerplate ...如何使用异步方法更新数据库中现有表中的记录? [英] Asp.Net Boilerplate... How to update a record in Existing tables in Database using Async methods?
本文介绍了Asp.Net Boilerplate ...如何使用异步方法更新数据库中现有表中的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 ASP.Net Boilerplate .通过电子邮件确认用户后,我想将isActive=true
发送到AbpUser
表.如何访问数据库并对此进行查询?
I am working with ASP.Net Boilerplate. I want to send isActive=true
to the AbpUser
table when a user is confirmed by email. How can I access the database and do a query on that?
您知道样板不提供实体类,因此我正在使用这些类的扩展.我不知道这些类上的查询如何访问数据库.有什么主意吗?
As you know Boilerplate doesn't provide entity classes so I am working with extensions on those classes. I don't know how queries on those classes access the database. Any idea?
推荐答案
我编写了一个示例代码,向您展示如何使用IRepository更新用户字段.
I wrote a sample code to show you how you can update a field of user with IRepository.
public interface IUserAppService: IApplicationService
{
void ActivateUser(int userId);
}
public class UserAppService : IUserAppService
{
private readonly IRepository<User, long> _userRepository;
public UserEmailer(IRepository<User, long> userRepository)
{
_userRepository = userRepository;
}
public void ActivateUser(int userId)
{
var user = _userRepository.Get(userId);
user.IsActive = true;
_userRepository.Update(user);
}
}
这篇关于Asp.Net Boilerplate ...如何使用异步方法更新数据库中现有表中的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文