Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Nested Tree Like Object Queries - How?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
wildThought - 15 Feb 2008 17:24 GMT
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?
Robbe Morris - [MVP] C# - 16 Feb 2008 20:58 GMT
Having spent several years working with complex unrelated hierarchies
like this, I can tell you it is far easier to manage each of these object
types
as entirely separate generic List<T>.  Then, writing Find predicate queries
against
each list that deal with all sorts of different scenarios is much, much
easier to support
as your app becomes more and more complex.

I realize the methodology you've used is considered "standard".  That said,
the way people did things years ago doesn't necessarily mean it is the best
fit for "your" app.

Signature

Robbe Morris [Microsoft MVP - Visual C#]
AdvancedXL Server, Designer, and Data Analyzer
Convert cell ranges in Excel to rule driven web apps
without IT programmers.
Free download:  http://www.equalssolved.com/default.aspx

> Given the following classes:
>
[quoted text clipped - 85 lines]
>
> How do I solve the above using Lamda?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.