[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
SolvedPrivate

LINQ: Need to do a Join on ManufacturerId

Posted on 2014-12-11
6
Medium Priority
?
39 Views
Last Modified: 2016-02-16
I have DealerManufacturers and each Manufacturer has a Bool property. I need the Count of DealerManufacturer which have that property as true.

public class Manufacturer
{
  public virtual id { get; set; }
  public virtual IsServiceable { get { return id != 45; } }
}

public class DealerManufacturer
{
        public virtual int DealerId  { get; set; }
        public virtual int ManufacturerId  { get; set; }
 }

I have numerous an IList<DealerManufacturers> in the model and need a count of those which are IsServiceable is TRUE

model.DealerManufacturers

Thanks.
0
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 40494423
Hi newbieweb;

Something like this should give you the count.

IList<DealerManufacturers> dmList = ....;
IList<Manufacturer> mList = ....;

var serviceable = (from dm in dmList
                   from m in mList
                   where dm.DealerId == m.id && m.IsServiceable == true
                   select dm).Count();

Open in new window

0
 

Author Comment

by:newbieweb
ID: 40494431
Sorry, I forgot to say. I only use the Fluent LINQ API...
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 1500 total points
ID: 40494491
var serviceableCount = dmList.Join(mList, 
                       dm => dm.DealerId, 
                       m => m.id,
                       (dm, m) => m.m.IsServiceable == true).Count();

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:newbieweb
ID: 40494606
I ended up using a different syntax and two queries. Is this inferior to yours? I could not get yours to work:

            IList<Manufacturer> newSaleManufacturers = DefaultRepository.FindByQuery(new FindManufacturersQuery()).Where(x => x.IsServiceable && x.IsNewSale).ToList();

            bool sellsNew = newSaleManufacturers.Where(x => model.DealerManufacturers.Select(y => y.ManufacturerId).Contains(x.Id)).Count() > 0;
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 40496349
Can you post how you implemented the solution I posted please.
0
 

Author Closing Comment

by:newbieweb
ID: 40507179
Sorry, no time. Your post helped.

Thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question