0%

20180822在家裡新增的工作日誌

RoleManager要先有Role才能新增AddToRoleAsync()

StackOverflow : userManager.AddToRoleAsync() - Error: role does not exist

1
2
3
4
5
6
7
8
// Add the Admin role to the database
IdentityResult roleResult;
bool adminRoleExists = await _roleManager.RoleExistsAsync("Admin");
if (!adminRoleExists)
{
_logger.LogInformation("Adding Admin role");
roleResult = await _roleManager.CreateAsync(new IdentityRole("Admin"));
}

C# One Line If-Else

每次都忘記
return (expression) ? value1 : value2;

C# Compiler Error : Inconsistent accessibility: parameter type is less accessible

原因是public的class內用到了inter的interface
安捏母湯

C#函数编译出错:Inconsistent accessibility: parameter type ‘aaa.bbb.ccc’ is less accessible than method ‘aaa.bbb.functionName(aaa.bbb.ccc)

C# Check Object is null

很簡單
if(data != null)

StackOverflow : Checking if an object is null in C#