score:1
this sql query is not correct, as you should bring what you have in select clause in group by clause (unless you use it in an aggregation function), so here you should use i.porcentaje
in group by, although i do not think grouping by something like percentage is what you want.
i guess you want to sum all the total_linea
considering porcentaje
, so, for example, you can write your query as this:
you have joined tables correctly, after joining, because you only need id_iva
and total_linea
and porcentaje
, gather only these values in an anonymous type,
then group them by id_iva
(as you did yourself), then choose values in your groupings and do your calculations:
var result = from l in linea_ventas
join i in ivas on l.id_iva equals i.id_iva
select new {
l.id_iva,
value = l.total_linea * i.porcentaje / 100
} into selected
group selected by selected.id_iva into groups
select groups.sum(v => v.value);
Source: stackoverflow.com
Related Query
- Convert SQL to LINQ with JOIN, GROUP BY, SUM, multiply values two List
- LINQ with JOIN, GROUP BY, ORDER BY, SUM, multiply values two List
- Linq to SQL With Left Outer Join and Group By With Sum - How To
- C# LINQ GroupBy to convert a List to a group with one property as List of values
- Convert Sql Query To linq using sum with group by
- Converting an SQL with Left Join , Group and Sum to a Linq Query
- left join with group by and sum in linq to sql
- Convert SQL to Linq with multiple joins , SUM and group by
- convert SQL query with multiple join on multiple tables using group by on multiple columns and with aggregate function into LINQ
- Convert SQL to Linq left join with null
- Convert a list to a dictionary and sum up values using linq
- How to convert list of objects with two fields to array with one of them using LINQ
- LINQ to SQL and Join two tables with OR clause
- LINQ to Sql Left Outer Join with Group By and Having Clause
- How should i use group by and sum on different values of list of models using linq
- Linq to SQL - Returning two values with one query
- Convert SQL IN clause with two columns into LINQ
- Linq to SQL Group by and sum in select with entity
- LINQ to SQL query Multiply two columns and calculate SUM
- How to convert multiple SQL LEFT JOIN statement with where clause to LINQ
- LINQ Join 2 Datatables and With SUM AND GROUP BY
- LINQ - Join 3 tables with group by and sum
- linq SQL statements for joining two id with single list
- How to convert SQL query to Linq with GROUP BY on only date part of a datetime?
- Convert SQL with multiple join into LINQ
- Help convert SQL statement to LINQ Lambda (need help with group by and sum)
- How to convert sql inner join query into linq to sql query and convert into list
- Convert simple Left Outer Join and group by SQL statement into Linq
- Convert Join and Group By from SQL to LINQ
- how to join two tables with comma separated values column in c# linq asp.net mvc
More Query from same tag
- select properties of entity ef linq
- Map array of strings to property in a List of objects C#
- Datatable Select all rows
- Why is C# OrderBy so fast?
- LINQ query with multiple joins throwing null reference error
- How to find maximum occured word from text?
- How can I join multiple count() statements into a single statement
- Extracting direction changes from a list of coordinates
- Linq GroupBy Projection with Multiple Groups
- Select a string in a list of strings linq
- Combine data gathered from different sources into one IEnumerable object
- How to OrderBy on a generic IEnumerable (IEnumerable<T>) using LINQ in C#?
- Using LINQ to convert List<U> to List<T>
- Refactoring the following LINQ query to perform better and look more simple
- Why is String.Contains case-insensitive in this query?
- Access Query in Linq
- query a class object using linq
- Groupby DateTime for specific intervals
- Linq - what locale/collation it uses to compare objects?
- Convert Python 3.x snippet to C#/LINQ
- Convert to date Format
- Entity Framework: Why can I not empty a collection in this Many-to-Many relations?
- Linq - how to subtract current index DateTime item with previous index DateTime item
- Optimize Linq code
- C# linq finding all string values in a list there match in mongodb
- Managing ranges with LINQ challenge
- LINQ Causing Invalid Cast?
- C# saving entity object outside of context
- Different behaviour between Join and SelectMany after replacing one of the sets
- Select distinct from List<t> ignoring one element