使用身份用户时遇到问题。调用Update(user)
后,数据库中的记录已更改。当我再次拨打Method(string userId)
,包含FindById(userId)
时,会出现此问题。 FindById(userId)
返回一个用户,所有记录仍然保留为第一个,尽管我之前已经更新过。
我实现用户表:
public class ApplicationUser : IdentityUser
{
public int MyProperty { set; get; }
}
用户经理类:
public class ApplicationUserManager : UserManager<ApplicationUser>, IApplicationUserManager
{
public Task MethodAsync(string userId)
{
// Find user
// return object before change (MyProperty not equal 1)
ApplicationUser user = await base.FindByIdAsync(userId);
user.MyProperty = 1;
await base.UpdateAsync()
}
}
答案 0 :(得分:0)
只有在更新当前登录用户的属性时才会发生这种情况吗?如果是这样,请尝试重新登录:
UserManager.FindById
用户对象可以从declare @tbl_name varchar(100)
declare @cl_name varchar(200)
declare Crs_tbl CURSOR FOR
select t.name
from sys.tables t
open Crs_tbl
fetch next from Crs_tbl into @tbl_name
while @@fetch_status=0
begin
declare Crs_columns CURSOR FOR
select c.name
from sys.columns c
where c.object_id=(select object_id from sys.tables where name=@tbl_name)
open Crs_columns
fetch next from Crs_columns into @cl_name
while @@FETCH_STATUS=0
begin
--check if value found on current column; if yes, store table and column information
close Crs_columns
Deallocate Crs_columns
end
end
close Crs_tbl
Deallocate Crs_tbl
方法获得。