score:1
Accepted answer
Use the ForEach
and Count
methods:
List<LeadImportViewModel> leadImportViewModelList = new List<LeadImportViewModel>();
List<LeadGridViewModel> leadGridViewModelList = new List<LeadGridViewModel>();
leadImportViewModelList.ForEach(vm => vm.QtyDuplicates
= leadGridViewModelList.Count(
gv => gv.CompanyNameStripped = vm.CompanyNameStripped));
score:0
Try
var coll = (from t1 in db.Leads_Staging
select new LeadImportViewModel
{
Id = t1.Id,
CompanyName = t1.CompanyName,
CompanyNameStripped = t1.CompanyNameStripped,
QtyDuplicates = db.LeadGridViewModel.Count(
gv => gv.CompanyNameStripped == t1.CompanyNameStripped)
});
score:1
It sounds like you just need:
var count = leadImports.Select(x => x.CompanyNameStripped))
.Intersect(leadGrids.Select(x => x.CompanyNameStripped)))
.Count();
Or:
var names = new HashSet<string>(leadImports.Select(x => x.CompanyNameStripped));
var count = leadGrids.Count(x => names.Contains(x.CompanyNameStripped));
score:1
list.Select(a => a.CompanyNameStripped).Intersect(list2.Select(b => b.CompanyNameStripped).Count()
Source: stackoverflow.com
Related Query
- Comparing collections and counting duplicates using LINQ and C#
- Poor performance comparing collections of objects using reflections and Linq Except/Intersect
- Listview, remove duplicates using LINQ and based in subitem comparing
- Convert list to dictionary using linq and not worrying about duplicates
- Comparing two collections with IEquatable while using only LINQ
- How can I code an outer join using LINQ and EF6?
- Using LINQ to remove duplicates in dictionary and the count of those duplicates
- Compare and check collections using LINQ
- Code Rewite for tuple and if else statements by using LINQ
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- Comparing and Merging Dictionaries using LINQ in C#
- Using linq to merge multiple XML files with the same structure and removing duplicates based on a key
- Comparing Complex Collections using Linq
- Comparing data from 2 tables and display the result on a dropdownlist using LINQ
- Take max date row from duplicates and remove duplicates in the list using linq
- Using nested LINQ queries and collections of objects
- How to remove duplicates from SQLite DB - using ENtity and LINQ
- Query XML using linq and comparing two variable
- Using linq and lambda to filter two collections
- Sorting, rounding and removing duplicates in a list of time stamps using LINQ
- Using LINQ to join [n] collections and find matches
- Using LINQ to Group, concatenate and Counting
- C# Linq Comparing List Values using multiple fields and return item which doesn't satisfy the condition
- Using linq to group by and merge property values of duplicates
- Need to count duplicates using linq and bind it to chart
- Getting rid of outer foreach loop using linq or lambda and ensuring no duplicates are added to list
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- Comparing child lists of objects using Linq and C#
- Querying the database using EF Code First and Linq
- Comparing 2 string arrays using Linq and Regex for a partial match
More Query from same tag
- Linq-to-sql many-many in database first
- Trouble binding XML child to DataList using ReadXML()
- Must find a users but how many antale
- Inner join in collections using LINQ
- C# Compare one List string with substring of other list string
- Nullable object must have a value - why?
- Expression of type 'System.DateTime' cannot be used for return type 'System.Object'
- How to get next item from list based on some condition in C#?
- Linq Extension Methods and Error Handling
- Linq to Entities Where In Clause Many to Many
- I don't want to use @html.Action and @Rendersection can any one guide me what i use
- Split a list in multiple lists per value of a certain property
- Lambda expression check if null helper
- Reuse function results in LINQ
- c# linq select list of objects looking inside another list of objects
- linq group by two columns and get only rows with same group by values
- LINQ order outer list by property of inner list
- Get indexes for intersection
- A lambda expression with a statement body cannot be converted to an expression tree in nopCommerce
- Partition By Logic in Code to calculate value of a DataTable Column
- How to return a driven collection of [List<>] after filtering by [Where]?
- How to retieve CRM Guid using LINQ and joins?
- Which ORM should i be using for .Net in 2016 to talk to SQL server?
- How to add more columns to a grouped result in LINQ?
- linq xml extract text between tags
- LINQ Update query with Join condition
- Non-Generated Property in LINQ to SQL insert behavior
- Linq segmenting data by status
- How to use LINQ to sort custom items by using StartWith
- LINQ to SQL bug (or very strange feature) when using IQueryable, foreach, and multiple Where