Sum object properties by its attribute using LINQ from multiple list

  • Thread starter Thread starter Shan1986
  • Start date Start date
S

Shan1986

Guest
Hallo I would like to write a LINQ query to sum object properties based on their attribute .

I have Datagridview like below. I want to loop through Datagridview Category column and write a sum of weights from two bindinglists.

1626283.jpg

Public Class Category1

<WeightVegitables()> _
Public Property Tomatto() As Integer

<WeightFruits()> _
Public Property Apple() As Integer

<WeightFruits()> _
Public Property Banana() As Integer

<WeightMeats()> __
Public Property Pork() As Integer

<WeightMeats()> __
Public Property Fish() As Integer

End Class
Public Class Categories1
Inherits System.ComponentModel.BindingList(Of Category1)
End Class




Public Class Category2

<WeightVegitables()> _
Public Property Brinjal() As Integer

<WeightFruits()> _
Public Property Orange() As Integer

<WeightMeats()> __
Public Property Chicken() As Integer

End Class
Public Class Categories2
Inherits System.ComponentModel.BindingList(Of Category2)
End Class

Or is there any alternative method to the example but without attributes?

Can i have more than 1 attribute to a property?

Thanks

Continue reading...
 
Back
Top