Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:18:38+00:00 2026-05-27T02:18:38+00:00

Im hoping someone can help me with a brain block I’m having about how

  • 0

Im hoping someone can help me with a brain block I’m having about how to do multiple joins with EF that returns an entity, where one of the fields is calculated by a query. Ive contrived a (pretty much useless) example in the hopes somebody can help me understand how this should be done.

Id like to return a list of ISPs entities from a DBContext with the “TotalUsed” property filled in by the LINQ query. Ive successfully done the joins (trivial), and have played with grouping and sum, but cant seem to get it quite right.

The general idea to this contrived example is that NICs are connected to one and only one router, and multiple routers are connected to a single ISP each.

How to write a LINQ query that sums the bandwidth needed for each ISP, along with the other properties in that ISP?

Expected output would be a list of ISP that might look like
{{1, “foo”, 52}, {2, “bar”, 345}, {3, “foobar”, 621}}, where the 3rd property is the summation of the BandwidthNeeded property on all NICs transitively related to ISP.

The classes:

public class ISP
{
   public int ISPid {get; set;}
    public int ISPName {get; set;}
    public int TotalUsed {get; set;}  // not mapped to DB -> should populate via LINQ
}

public class Router
{
    public int RouterId {get; set;}
    public string RouterName {get; set;}
    public int ISPId {get; set;} // foreign key for ISP
}  

public class Nic
{
    public int NicId { get; set; }
    public string NicLocation { get; set; }
    public int BandwidthUsed { get; set; }
    public int RouterId {get; set; }  // foreign key for router
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:18:38+00:00Added an answer on May 27, 2026 at 2:18 am

    If you move the TotalUsed property into a separate type, you could do this (please excuse any typos):

    public class ISP // mapped
    {
        public int ISPid {get; set;}
        public int ISPName {get; set;}
    }
    public class ISPWithTotalUsed : ISP // not mapped
    {
        public int TotalUsed { get; set; }
    }
    var query = (from ISP in context.ISPs
                 select new ISPWithTotalUsed
                 {
                     ISPid = ISP.ISPid,
                     ISPName = ISP.ISPName,
                     TotalUsed = (from router in context.Routers
                                  where router.ISPid == ISP.ISPid
                                  from nic in context.Nics
                                  where nic.RouterId == router.RouterId
                                  select nic.BandwidthUsed).Sum()
                 });
    

    If you add navigation properties, it could be made somewhat more readable by removing the links on ID.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of a brain fart here, and hoping someone can help
I'm hoping someone can help. I'm sure its just a simple one that I
Alright, I am hoping someone can help me out. I apologize up front that
I'm hoping someone can help me with this annoying little problem I'm having. I'm
I'm really hoping someone can help me out with this one. I've been stuck
I'm hoping that someone can help me with this issue. I've been racking my
I'm hoping someone can help with this, I'm having a really difficult time getting
I'm hoping someone can help me. I've got a specific Exception from COM that
Hoping someone can help with this. I have other VM's that dont have problems,
Im hoping someone can help me out with a problem Im having with using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.