W
wildThought
Given the following classes:
public class aUser
{
public string name;
public UserRole[] userRoles;
}
public class userRole
{
public string roleName;
public ApplicationRole[] applicationRoles;
}
public class ApplicationRole
{
public AProcess[] theProcesses;
}
public class AProcess
{
public string processName;
}
I can
string processName =
aUser.userRoles[0].applicationRoles[0].theProcesses[0].processName
How can I find out if a user has a processName that matches a given
string anywhere nested in the userRoles > ApplicationRoles >
TheProcessesCollection > ProcessInstance
If I was going to do this without LINQ or Lambdas
foreach(userRole role in user.userRoles)
{
foreach(ApplicationRole appRole in role.applicationRoles)
{
foreach(AProcess proc in appRole.theProcesses)
{
if(proc.processName == 'SomeProcessString')
{
return true;
}
}
}
}
IN SQL we could join a bunch of tables together and select a count(*)
into a variable to accomplish the same task.
Select count(*)
FROM User u
JOIN UserRole ur ON (ur.UserID = u.UserID)
JOIN ApplicationRole ar ON (ar.RoleID = ur.RoleID)
JOIN RoleProcesses rp ON (rp.RoleID = ar.RoleID)
JOIN Process p ON (p.ProcessID = rp.ProcessID)
WHERE p.ProcessName = 'Some Process Name'
How do I solve the above using LINQtoSQL?
How do I solve the above using Lamda?
public class aUser
{
public string name;
public UserRole[] userRoles;
}
public class userRole
{
public string roleName;
public ApplicationRole[] applicationRoles;
}
public class ApplicationRole
{
public AProcess[] theProcesses;
}
public class AProcess
{
public string processName;
}
I can
string processName =
aUser.userRoles[0].applicationRoles[0].theProcesses[0].processName
How can I find out if a user has a processName that matches a given
string anywhere nested in the userRoles > ApplicationRoles >
TheProcessesCollection > ProcessInstance
If I was going to do this without LINQ or Lambdas
foreach(userRole role in user.userRoles)
{
foreach(ApplicationRole appRole in role.applicationRoles)
{
foreach(AProcess proc in appRole.theProcesses)
{
if(proc.processName == 'SomeProcessString')
{
return true;
}
}
}
}
IN SQL we could join a bunch of tables together and select a count(*)
into a variable to accomplish the same task.
Select count(*)
FROM User u
JOIN UserRole ur ON (ur.UserID = u.UserID)
JOIN ApplicationRole ar ON (ar.RoleID = ur.RoleID)
JOIN RoleProcesses rp ON (rp.RoleID = ar.RoleID)
JOIN Process p ON (p.ProcessID = rp.ProcessID)
WHERE p.ProcessName = 'Some Process Name'
How do I solve the above using LINQtoSQL?
How do I solve the above using Lamda?