Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

How to include Data from Table Above

$
0
0

Not quite sure how to explain this please bear with me.

I have a table Client.

Table Client has a relationship one to many with Sites.

Sites has a relationship one to many with Jobs.

In Jobs I want to add a print detail view.  This will include the clients details.

 public async Task<IActionResult> PrintDetails(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            var job = await _context.Job
                .Include(m=>m.Site)
                .Include(m => m.WaterBody)
                .AsNoTracking()
                .SingleOrDefaultAsync(m => m.JobID == id);


            if (job == null)
            {
                return NotFound();
            }

            return View(job);
        }

Is my current code, which is returning all the correct data...except the Client data.  I am not sure how to add something like:

Include All from Client Where SiteID is included in Client Records

Can someone either show me the correct syntax to put this into the Include statements?  Or can someone show me how to rewrite as a query to return the record required?

And to help me for future, as I cant work it out form the tutorials, what is the:

var job = await _context.Job
                .Include(m=>m.Site)
                .Include(m => m.WaterBody)
                .AsNoTracking()
                .SingleOrDefaultAsync(m => m.JobID == id);

type statement called so I can correctly google for help on it in future?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>