As shown below, my Azure Portal
is correctly displaying the Source
column value as Windows Server AD
for the users that were migrated from Windows Active Directory
to Azure Active Directory
.
Users shown in Azure Portal:
Now in my WPF
app, I am using Microsoft Graph to display the same list in a DataGrid
. But the following LINQ
query is still displaying the Source
column value of the migrated users as Azure Active Directory
instead of Windows Server AD
:
var users = await graphClient.Users
.Request()
.Select("displayName, userPrincipalName, onPremisesUserPrincipalName, userType")
.GetAsync();
List<User> lstUsers = (List<User>)users.CurrentPage.ToList();
//I noticed the following Linq without lambda works better if select case staement have multiple conditions: https://stackoverflow.com/a/936136/1232087
var userslist =
(
from User in lstUsers
select new
{
DisplayName = User.DisplayName,
UserPrincipalName = User.UserPrincipalName,
OnPremisesUserPrincipalName = User.OnPremisesUserPrincipalName,
UserType = User.UserType,
Source =
(
User.UserType == "Member" && !User.UserPrincipalName.Contains("#EXT#") ? "Azure Active Directory" :
User.UserType == "Member" && User.UserPrincipalName.Contains("#EXT#") ? "Microsoft Account" :
User.UserType == "Guest" && User.ExternalUserState == "Accepted" ? "External Azure Active Directory" :
(User.UserType == "Member" && string.IsNullOrEmpty(User.OnPremisesUserPrincipalName) == false) ? "Windows Server AD" :
User.UserType == "Guest" && User.ExternalUserState == "PendingAcceptance" ? "Invited user" : "Unknown"
)
}
);
DataGrid display of the above query result in my WPF app:
According to above LINQ query, values inside red should have displayed as Windows Server AD
because OnPremisesUserPrincipalName
value of the query (shown in On Prem Name
column below) are not null
Question: Why the above LINQ
query is returning the Source
column value as Azure Active Directory
instead of Windows Server AD
. This seems to be a LINQ related issue unless I'm missing something here. There are similar LINQ examples here and here.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…