c# - How can I query this hierarchical data using LINQ? -


I have 3 types of objects: Agency, BusinessUnnet and Client (with their own table)

< P> In terms of hierarchy, agencies themselves are own customers of Business Units and Business Universe.

I have 3C # Poko objects, to represent them (instead of using LINQ Generated classes I usually choose them from the new ones):

Public Sector Agency {PUBLIC INIMMERABLE & lt; BusinessUnit & gt; BusinessUnits {get; Set; }} Public Sector BusinessUnit {Public IEnumerable & lt; Customers & gt; Customer {Received; Set; }} Public Class Client {Public Entry Number of Extensions {Received; Set; } {Get the location of the public decimal amount; Set; } Public Decimal AGB Annex {Received; Set; } Public double planning scores {received; Set; }}

You can see that there is a list of BusinessUnits in the agencies, and BusinessUnits has a list of clients.

I also have a mapping table called BAC_Map in the database that says which is the owner and it looks like this:

How can I create a query, so I can query for a list of agencies? That means, I want every agency to prepare a list of business items, and I want to set the list of business objects in the list of customers.

I can do basic LINQ queries, but is it a little bit related to map tables and many on my head? Inquiries

How can I create a method like GetAllAgencies () which will only inquire for all the agencies, but its business will populate the Uninets, which is the owner of the agency, and those business customers Is the owner?


Edit: Any suggestions or info is appreciated Do I need to get involved? Does it need to have several questions to return to an agency list, with its submembers populated?

If you drop all the four tables (Agency, BusinessUnnet, Client, Map) for SQL Designer on Linq, , And to draw relationships from map to second, there may be some useful properties on the map.

  // Create a query to return the results of the row / column size var query = m to db.map // where m ....? Let's do a = m. Agency give b = m Business Unit C = M Client // where is something about A or B or C? Select new {AgencyID = a.AgencyID, AgencyName = a.Name, BusinessUnitID = b.BusinessUnitID, ClientID = c.ClientID, NumberOfAccounts = c.NumberOfAccounts, Score = c.Score}; // database var rawRecords = query.ToList (); // Resize the results further in the hierarchy & lt; Agency & gt; Results = Raw spaces. Gutback (x => x.AgencyID). Select (g = & gt; new agency () {name = g. Firstly}. Agency Name, BusinessUnits = g. Gutback (y = & gt; y.BusinessUnitID). Select (g2 = & gt; New BusinessUnit () {Client = G2} (z = & gt; New Client () {NumberOfAccounts = z.NumberOfAccounts, Score = z.Score})})}) .Olist () ;  

If approval filters are provided (see where segments are commented), then only the necessary tables will be drawn into memory. Is the standard SQL to be.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -