Count every data that grouped in list
I'm trying to count total data that grouped in my list.
So here is my code:
List<InventoryViewModel> temp =
InventoriesByLocation.GroupBy(s => s.ProductId).Select(group => group.First()).ToList();
I want to count how many productId
that already groupby().
c# list linq
add a comment |
I'm trying to count total data that grouped in my list.
So here is my code:
List<InventoryViewModel> temp =
InventoriesByLocation.GroupBy(s => s.ProductId).Select(group => group.First()).ToList();
I want to count how many productId
that already groupby().
c# list linq
2
MoreLINQ's CountBy may be worth considering - markheath.net/post/exploring-morelinq-17-countby .
– mjwills
Nov 11 '18 at 20:50
So basically you want to count how many unique productId's there is in the list?InventoriesByLocation.Select(x => ProductId).Distinct().Count()
– Magnus
Nov 12 '18 at 9:09
add a comment |
I'm trying to count total data that grouped in my list.
So here is my code:
List<InventoryViewModel> temp =
InventoriesByLocation.GroupBy(s => s.ProductId).Select(group => group.First()).ToList();
I want to count how many productId
that already groupby().
c# list linq
I'm trying to count total data that grouped in my list.
So here is my code:
List<InventoryViewModel> temp =
InventoriesByLocation.GroupBy(s => s.ProductId).Select(group => group.First()).ToList();
I want to count how many productId
that already groupby().
c# list linq
c# list linq
edited Nov 11 '18 at 20:52
Uwe Keim
27.5k32130211
27.5k32130211
asked Nov 11 '18 at 20:17
Yeremia DanangYeremia Danang
558
558
2
MoreLINQ's CountBy may be worth considering - markheath.net/post/exploring-morelinq-17-countby .
– mjwills
Nov 11 '18 at 20:50
So basically you want to count how many unique productId's there is in the list?InventoriesByLocation.Select(x => ProductId).Distinct().Count()
– Magnus
Nov 12 '18 at 9:09
add a comment |
2
MoreLINQ's CountBy may be worth considering - markheath.net/post/exploring-morelinq-17-countby .
– mjwills
Nov 11 '18 at 20:50
So basically you want to count how many unique productId's there is in the list?InventoriesByLocation.Select(x => ProductId).Distinct().Count()
– Magnus
Nov 12 '18 at 9:09
2
2
MoreLINQ's CountBy may be worth considering - markheath.net/post/exploring-morelinq-17-countby .
– mjwills
Nov 11 '18 at 20:50
MoreLINQ's CountBy may be worth considering - markheath.net/post/exploring-morelinq-17-countby .
– mjwills
Nov 11 '18 at 20:50
So basically you want to count how many unique productId's there is in the list?
InventoriesByLocation.Select(x => ProductId).Distinct().Count()
– Magnus
Nov 12 '18 at 9:09
So basically you want to count how many unique productId's there is in the list?
InventoriesByLocation.Select(x => ProductId).Distinct().Count()
– Magnus
Nov 12 '18 at 9:09
add a comment |
2 Answers
2
active
oldest
votes
So you have a sequence of InventoryViewModels
, where every InventoryViewModel
has a ProductId
.
You want to group all InventoryViewModels
into groups, where every groups contains all InventoryViewModels
with the same ProductId
. After that you want to count the number of InventoryViewModels
in each group, and possibly also some other items. Your example code takes the first element in the group.
var groupsWithSameProductId = inventoryViewModels
.GroupBy(inventoryViewModel => inventoryViewModel.ProductId)
Now every group has a Key
, which contains the ProductId
that is the same for all elements in your group. The group itself is a sequence of all InventoryViewModels
that have the ProductId
equal to the Key
.
To get the number of InventoryViewModels
that have this ProductId
, just Count()
them. If you want other items, just Select
them:
// continue the LINQ statement
.Select(group => new
ProductId = group.Key,
NrOfInventroyViewModelsWithThisProductId = group.Count(),
// only if you want other items:
FirstInventoryViewModel = group.First(),
Names = group.Select(groupItem => groupItem.Name).ToList(),
);
Note, that every groupItem
is an InventoryViewModel
with ProductId
equal to group.Key
There is an overload of Enumerable.GroupBy that combines the grouping and selecting in one statement:
var result = inventoryViewModels
.GroupBy(inventoryViewModel => inventoryViewModel.ProductId, // make groups with same productId
(commonProductId, inventoryViewModelsWithThisCommonProductId) => new
ProductId = commonProductId,
Count = inventoryViewModelsWithThisCommonProductId.Count(),
Names = inventoryViewModelsWithThisCommonProductId
.Select(inventoryViewModelWithThisCommonProductId.Name)
.ToList(),
);
thanks for your explanation and i get it. but i gotAnonymous Type: a is newGuid ProductId,int NrOfInventroyViewModelsWithThisProductId
and can i get the same type of list. Or the selected item cant turn into same type of list. In this case:List<inventoryfiewmodel> mInventories= var result
/selected inventorylist/??
– Yeremia Danang
Nov 12 '18 at 12:35
I don't know your classInventoryViewModel
. If it has similar properties, you can usenew InventoryViewModel()
, if it is quite different, then I wonder why you would like to do that. The idea behind object oriented programming is that a dog is different than a cat, so don't try to put a can in a dog object
– Harald Coppoolse
Nov 13 '18 at 10:00
List<InventoryViewModel> InventoriesByLocation = temp.Join(StorageByLocation, i => i.StorageId, s => s.Id, (i, s) => i).Where(i=> i.ExpirationDate<DateTime.Now).GroupBy(s => s.ProductId).Select(g=>new g.Key,Count=g.Count()).ToList();
this is my code. Variable temp isList<inventoryViewModel>
too. I need to put the grouped list toList<InventoryViewModel>
or put them into variabel that I can access publicly. I can't send var (local variable) to my function.
– Yeremia Danang
Nov 14 '18 at 11:34
ohh haha, thanks
– Yeremia Danang
Nov 14 '18 at 11:51
add a comment |
Something like this:
var count = InventoriesByLocation.GroupBy(s => s.ProductId).Count();
Basically, GroupBy
returns a type roughly equivalent to IDictionary<int, InventoryViewModel>
in your case. So, length of an individual dictionary entry will be the count of a unique ProductId
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252830%2fcount-every-data-that-grouped-in-list%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
So you have a sequence of InventoryViewModels
, where every InventoryViewModel
has a ProductId
.
You want to group all InventoryViewModels
into groups, where every groups contains all InventoryViewModels
with the same ProductId
. After that you want to count the number of InventoryViewModels
in each group, and possibly also some other items. Your example code takes the first element in the group.
var groupsWithSameProductId = inventoryViewModels
.GroupBy(inventoryViewModel => inventoryViewModel.ProductId)
Now every group has a Key
, which contains the ProductId
that is the same for all elements in your group. The group itself is a sequence of all InventoryViewModels
that have the ProductId
equal to the Key
.
To get the number of InventoryViewModels
that have this ProductId
, just Count()
them. If you want other items, just Select
them:
// continue the LINQ statement
.Select(group => new
ProductId = group.Key,
NrOfInventroyViewModelsWithThisProductId = group.Count(),
// only if you want other items:
FirstInventoryViewModel = group.First(),
Names = group.Select(groupItem => groupItem.Name).ToList(),
);
Note, that every groupItem
is an InventoryViewModel
with ProductId
equal to group.Key
There is an overload of Enumerable.GroupBy that combines the grouping and selecting in one statement:
var result = inventoryViewModels
.GroupBy(inventoryViewModel => inventoryViewModel.ProductId, // make groups with same productId
(commonProductId, inventoryViewModelsWithThisCommonProductId) => new
ProductId = commonProductId,
Count = inventoryViewModelsWithThisCommonProductId.Count(),
Names = inventoryViewModelsWithThisCommonProductId
.Select(inventoryViewModelWithThisCommonProductId.Name)
.ToList(),
);
thanks for your explanation and i get it. but i gotAnonymous Type: a is newGuid ProductId,int NrOfInventroyViewModelsWithThisProductId
and can i get the same type of list. Or the selected item cant turn into same type of list. In this case:List<inventoryfiewmodel> mInventories= var result
/selected inventorylist/??
– Yeremia Danang
Nov 12 '18 at 12:35
I don't know your classInventoryViewModel
. If it has similar properties, you can usenew InventoryViewModel()
, if it is quite different, then I wonder why you would like to do that. The idea behind object oriented programming is that a dog is different than a cat, so don't try to put a can in a dog object
– Harald Coppoolse
Nov 13 '18 at 10:00
List<InventoryViewModel> InventoriesByLocation = temp.Join(StorageByLocation, i => i.StorageId, s => s.Id, (i, s) => i).Where(i=> i.ExpirationDate<DateTime.Now).GroupBy(s => s.ProductId).Select(g=>new g.Key,Count=g.Count()).ToList();
this is my code. Variable temp isList<inventoryViewModel>
too. I need to put the grouped list toList<InventoryViewModel>
or put them into variabel that I can access publicly. I can't send var (local variable) to my function.
– Yeremia Danang
Nov 14 '18 at 11:34
ohh haha, thanks
– Yeremia Danang
Nov 14 '18 at 11:51
add a comment |
So you have a sequence of InventoryViewModels
, where every InventoryViewModel
has a ProductId
.
You want to group all InventoryViewModels
into groups, where every groups contains all InventoryViewModels
with the same ProductId
. After that you want to count the number of InventoryViewModels
in each group, and possibly also some other items. Your example code takes the first element in the group.
var groupsWithSameProductId = inventoryViewModels
.GroupBy(inventoryViewModel => inventoryViewModel.ProductId)
Now every group has a Key
, which contains the ProductId
that is the same for all elements in your group. The group itself is a sequence of all InventoryViewModels
that have the ProductId
equal to the Key
.
To get the number of InventoryViewModels
that have this ProductId
, just Count()
them. If you want other items, just Select
them:
// continue the LINQ statement
.Select(group => new
ProductId = group.Key,
NrOfInventroyViewModelsWithThisProductId = group.Count(),
// only if you want other items:
FirstInventoryViewModel = group.First(),
Names = group.Select(groupItem => groupItem.Name).ToList(),
);
Note, that every groupItem
is an InventoryViewModel
with ProductId
equal to group.Key
There is an overload of Enumerable.GroupBy that combines the grouping and selecting in one statement:
var result = inventoryViewModels
.GroupBy(inventoryViewModel => inventoryViewModel.ProductId, // make groups with same productId
(commonProductId, inventoryViewModelsWithThisCommonProductId) => new
ProductId = commonProductId,
Count = inventoryViewModelsWithThisCommonProductId.Count(),
Names = inventoryViewModelsWithThisCommonProductId
.Select(inventoryViewModelWithThisCommonProductId.Name)
.ToList(),
);
thanks for your explanation and i get it. but i gotAnonymous Type: a is newGuid ProductId,int NrOfInventroyViewModelsWithThisProductId
and can i get the same type of list. Or the selected item cant turn into same type of list. In this case:List<inventoryfiewmodel> mInventories= var result
/selected inventorylist/??
– Yeremia Danang
Nov 12 '18 at 12:35
I don't know your classInventoryViewModel
. If it has similar properties, you can usenew InventoryViewModel()
, if it is quite different, then I wonder why you would like to do that. The idea behind object oriented programming is that a dog is different than a cat, so don't try to put a can in a dog object
– Harald Coppoolse
Nov 13 '18 at 10:00
List<InventoryViewModel> InventoriesByLocation = temp.Join(StorageByLocation, i => i.StorageId, s => s.Id, (i, s) => i).Where(i=> i.ExpirationDate<DateTime.Now).GroupBy(s => s.ProductId).Select(g=>new g.Key,Count=g.Count()).ToList();
this is my code. Variable temp isList<inventoryViewModel>
too. I need to put the grouped list toList<InventoryViewModel>
or put them into variabel that I can access publicly. I can't send var (local variable) to my function.
– Yeremia Danang
Nov 14 '18 at 11:34
ohh haha, thanks
– Yeremia Danang
Nov 14 '18 at 11:51
add a comment |
So you have a sequence of InventoryViewModels
, where every InventoryViewModel
has a ProductId
.
You want to group all InventoryViewModels
into groups, where every groups contains all InventoryViewModels
with the same ProductId
. After that you want to count the number of InventoryViewModels
in each group, and possibly also some other items. Your example code takes the first element in the group.
var groupsWithSameProductId = inventoryViewModels
.GroupBy(inventoryViewModel => inventoryViewModel.ProductId)
Now every group has a Key
, which contains the ProductId
that is the same for all elements in your group. The group itself is a sequence of all InventoryViewModels
that have the ProductId
equal to the Key
.
To get the number of InventoryViewModels
that have this ProductId
, just Count()
them. If you want other items, just Select
them:
// continue the LINQ statement
.Select(group => new
ProductId = group.Key,
NrOfInventroyViewModelsWithThisProductId = group.Count(),
// only if you want other items:
FirstInventoryViewModel = group.First(),
Names = group.Select(groupItem => groupItem.Name).ToList(),
);
Note, that every groupItem
is an InventoryViewModel
with ProductId
equal to group.Key
There is an overload of Enumerable.GroupBy that combines the grouping and selecting in one statement:
var result = inventoryViewModels
.GroupBy(inventoryViewModel => inventoryViewModel.ProductId, // make groups with same productId
(commonProductId, inventoryViewModelsWithThisCommonProductId) => new
ProductId = commonProductId,
Count = inventoryViewModelsWithThisCommonProductId.Count(),
Names = inventoryViewModelsWithThisCommonProductId
.Select(inventoryViewModelWithThisCommonProductId.Name)
.ToList(),
);
So you have a sequence of InventoryViewModels
, where every InventoryViewModel
has a ProductId
.
You want to group all InventoryViewModels
into groups, where every groups contains all InventoryViewModels
with the same ProductId
. After that you want to count the number of InventoryViewModels
in each group, and possibly also some other items. Your example code takes the first element in the group.
var groupsWithSameProductId = inventoryViewModels
.GroupBy(inventoryViewModel => inventoryViewModel.ProductId)
Now every group has a Key
, which contains the ProductId
that is the same for all elements in your group. The group itself is a sequence of all InventoryViewModels
that have the ProductId
equal to the Key
.
To get the number of InventoryViewModels
that have this ProductId
, just Count()
them. If you want other items, just Select
them:
// continue the LINQ statement
.Select(group => new
ProductId = group.Key,
NrOfInventroyViewModelsWithThisProductId = group.Count(),
// only if you want other items:
FirstInventoryViewModel = group.First(),
Names = group.Select(groupItem => groupItem.Name).ToList(),
);
Note, that every groupItem
is an InventoryViewModel
with ProductId
equal to group.Key
There is an overload of Enumerable.GroupBy that combines the grouping and selecting in one statement:
var result = inventoryViewModels
.GroupBy(inventoryViewModel => inventoryViewModel.ProductId, // make groups with same productId
(commonProductId, inventoryViewModelsWithThisCommonProductId) => new
ProductId = commonProductId,
Count = inventoryViewModelsWithThisCommonProductId.Count(),
Names = inventoryViewModelsWithThisCommonProductId
.Select(inventoryViewModelWithThisCommonProductId.Name)
.ToList(),
);
answered Nov 12 '18 at 8:17
Harald CoppoolseHarald Coppoolse
12.1k12960
12.1k12960
thanks for your explanation and i get it. but i gotAnonymous Type: a is newGuid ProductId,int NrOfInventroyViewModelsWithThisProductId
and can i get the same type of list. Or the selected item cant turn into same type of list. In this case:List<inventoryfiewmodel> mInventories= var result
/selected inventorylist/??
– Yeremia Danang
Nov 12 '18 at 12:35
I don't know your classInventoryViewModel
. If it has similar properties, you can usenew InventoryViewModel()
, if it is quite different, then I wonder why you would like to do that. The idea behind object oriented programming is that a dog is different than a cat, so don't try to put a can in a dog object
– Harald Coppoolse
Nov 13 '18 at 10:00
List<InventoryViewModel> InventoriesByLocation = temp.Join(StorageByLocation, i => i.StorageId, s => s.Id, (i, s) => i).Where(i=> i.ExpirationDate<DateTime.Now).GroupBy(s => s.ProductId).Select(g=>new g.Key,Count=g.Count()).ToList();
this is my code. Variable temp isList<inventoryViewModel>
too. I need to put the grouped list toList<InventoryViewModel>
or put them into variabel that I can access publicly. I can't send var (local variable) to my function.
– Yeremia Danang
Nov 14 '18 at 11:34
ohh haha, thanks
– Yeremia Danang
Nov 14 '18 at 11:51
add a comment |
thanks for your explanation and i get it. but i gotAnonymous Type: a is newGuid ProductId,int NrOfInventroyViewModelsWithThisProductId
and can i get the same type of list. Or the selected item cant turn into same type of list. In this case:List<inventoryfiewmodel> mInventories= var result
/selected inventorylist/??
– Yeremia Danang
Nov 12 '18 at 12:35
I don't know your classInventoryViewModel
. If it has similar properties, you can usenew InventoryViewModel()
, if it is quite different, then I wonder why you would like to do that. The idea behind object oriented programming is that a dog is different than a cat, so don't try to put a can in a dog object
– Harald Coppoolse
Nov 13 '18 at 10:00
List<InventoryViewModel> InventoriesByLocation = temp.Join(StorageByLocation, i => i.StorageId, s => s.Id, (i, s) => i).Where(i=> i.ExpirationDate<DateTime.Now).GroupBy(s => s.ProductId).Select(g=>new g.Key,Count=g.Count()).ToList();
this is my code. Variable temp isList<inventoryViewModel>
too. I need to put the grouped list toList<InventoryViewModel>
or put them into variabel that I can access publicly. I can't send var (local variable) to my function.
– Yeremia Danang
Nov 14 '18 at 11:34
ohh haha, thanks
– Yeremia Danang
Nov 14 '18 at 11:51
thanks for your explanation and i get it. but i got
Anonymous Type: a is newGuid ProductId,int NrOfInventroyViewModelsWithThisProductId
and can i get the same type of list. Or the selected item cant turn into same type of list. In this case: List<inventoryfiewmodel> mInventories= var result
/selected inventorylist/??– Yeremia Danang
Nov 12 '18 at 12:35
thanks for your explanation and i get it. but i got
Anonymous Type: a is newGuid ProductId,int NrOfInventroyViewModelsWithThisProductId
and can i get the same type of list. Or the selected item cant turn into same type of list. In this case: List<inventoryfiewmodel> mInventories= var result
/selected inventorylist/??– Yeremia Danang
Nov 12 '18 at 12:35
I don't know your class
InventoryViewModel
. If it has similar properties, you can use new InventoryViewModel()
, if it is quite different, then I wonder why you would like to do that. The idea behind object oriented programming is that a dog is different than a cat, so don't try to put a can in a dog object– Harald Coppoolse
Nov 13 '18 at 10:00
I don't know your class
InventoryViewModel
. If it has similar properties, you can use new InventoryViewModel()
, if it is quite different, then I wonder why you would like to do that. The idea behind object oriented programming is that a dog is different than a cat, so don't try to put a can in a dog object– Harald Coppoolse
Nov 13 '18 at 10:00
List<InventoryViewModel> InventoriesByLocation = temp.Join(StorageByLocation, i => i.StorageId, s => s.Id, (i, s) => i).Where(i=> i.ExpirationDate<DateTime.Now).GroupBy(s => s.ProductId).Select(g=>new g.Key,Count=g.Count()).ToList();
this is my code. Variable temp is List<inventoryViewModel>
too. I need to put the grouped list to List<InventoryViewModel>
or put them into variabel that I can access publicly. I can't send var (local variable) to my function.– Yeremia Danang
Nov 14 '18 at 11:34
List<InventoryViewModel> InventoriesByLocation = temp.Join(StorageByLocation, i => i.StorageId, s => s.Id, (i, s) => i).Where(i=> i.ExpirationDate<DateTime.Now).GroupBy(s => s.ProductId).Select(g=>new g.Key,Count=g.Count()).ToList();
this is my code. Variable temp is List<inventoryViewModel>
too. I need to put the grouped list to List<InventoryViewModel>
or put them into variabel that I can access publicly. I can't send var (local variable) to my function.– Yeremia Danang
Nov 14 '18 at 11:34
ohh haha, thanks
– Yeremia Danang
Nov 14 '18 at 11:51
ohh haha, thanks
– Yeremia Danang
Nov 14 '18 at 11:51
add a comment |
Something like this:
var count = InventoriesByLocation.GroupBy(s => s.ProductId).Count();
Basically, GroupBy
returns a type roughly equivalent to IDictionary<int, InventoryViewModel>
in your case. So, length of an individual dictionary entry will be the count of a unique ProductId
.
add a comment |
Something like this:
var count = InventoriesByLocation.GroupBy(s => s.ProductId).Count();
Basically, GroupBy
returns a type roughly equivalent to IDictionary<int, InventoryViewModel>
in your case. So, length of an individual dictionary entry will be the count of a unique ProductId
.
add a comment |
Something like this:
var count = InventoriesByLocation.GroupBy(s => s.ProductId).Count();
Basically, GroupBy
returns a type roughly equivalent to IDictionary<int, InventoryViewModel>
in your case. So, length of an individual dictionary entry will be the count of a unique ProductId
.
Something like this:
var count = InventoriesByLocation.GroupBy(s => s.ProductId).Count();
Basically, GroupBy
returns a type roughly equivalent to IDictionary<int, InventoryViewModel>
in your case. So, length of an individual dictionary entry will be the count of a unique ProductId
.
edited Nov 11 '18 at 20:52
mjwills
15.3k42440
15.3k42440
answered Nov 11 '18 at 20:20
Sergey ShulikSergey Shulik
678824
678824
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252830%2fcount-every-data-that-grouped-in-list%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
MoreLINQ's CountBy may be worth considering - markheath.net/post/exploring-morelinq-17-countby .
– mjwills
Nov 11 '18 at 20:50
So basically you want to count how many unique productId's there is in the list?
InventoriesByLocation.Select(x => ProductId).Distinct().Count()
– Magnus
Nov 12 '18 at 9:09