score:2
Take a look at tis fragment:
group N by N.STG_nt into G
The part between by
and into
is the key(s), and similar to SQL there you have access to all aliases (variables) from from
and join
clauses. The name after into
is LINQ specific and represents the alias (variable) for accessing the GroupBy
result. But what is between group
and 'by'? There is no SQL equivalent.
Well, the result of GroupBy
is of type IGrouping<TKey, TElement>
, which has property TKey Key
and also is IEnumerable<TElement>
. The TKey
is comong from the expression between by
and into
, while TElement
(which is what you can access through into
variable is coming from the expression between group
and by
.
In your sample you've put N
there, that`s why you have access only to its properties.
In order to have access to other properties, you would use the typical LINQ construct for "composite" things, which is anonymous type projection, e.g.
var R = (
from N in SCHOOL_DB_Context.Con.NT_CTR
join S in SCHOOL_DB_Context.Con.STGs on N.STG_nt equals S.CD_STG
where N.CTR_nt == CTR
group new { N, S } by N.STG_nt into G
select new NT_CTR_Anal
{
G.Key, // N.STG_nt
SomeNPropSum = G.Sum(e => e.N.SomeNProp),
SomeSPropSum = G.Sum(e => e.S.SomeSProp),
};
As you can see, now you have access to both N
and S
properties inside grouping aggregate methods.
Source: stackoverflow.com
Related Query
- Get properties from second (Right) joined entity with Group by
- Join a list with an entity and get the average from the second table
- Get max & min from Entity Framework, in one query and with best query possible
- How get database table name with schema name from entity programmatically
- How to get number of objects with common properties from context using LINQ
- Using linq group by to get from a list of objects with a DateTime property to a list with an interval StartDate, EndDate
- Combine Two Properties From Entity In List And Flatten It With Linq
- Linq query with select needed to get specific properties from a list
- How to get identity from multiple objects when adding those with Entity Framework?
- Create a entity framework LINQ group join query to return a subset of properties from DTO and a list of another DTO, ASP.net core
- Get image from SQL Server into datagrid with wpf C# Ado.Net Data Entity
- How do i get specific columns from a thenInclude using Include with Multiple Levels of Properties
- get selected value from combobox with data source is anonymous type
- LINQ - Get records from one table, with second table multi record matching
- How to get count with using COUNT_BIG() from Entity Framework
- Get objects from dictionary with equal properties values for every Key
- Faster alternative to populate data in list from second list with other properties
- How to get first row from DB using Entity Framework where column starts with certain string and continues with numeric characters
- LINQ Get Data from 2 tables in 1 join with group by
- How to Group By make Distinct from two Properties has same entity in C# Linq
- How I get the right Data from my Column with Linq
- How do I get the object with the second latest date from a collection of objects
- Using LINQ and Entity Framework, how can I just populate some properties of a Dbo with data from the DB?
- How to get Entity from DB including navigation properties and child list total amount
- Group By, Take First with a vale from second
- With EF, when you group by, is that a projection? How to get joined columns
- Get Random number of lines from textfile with group by
- How to get data from two tables but with where clause on the second (FOREIGN KEY) table? [LINQ]
- Entity Framework dynamic linq where from generic source with dynamic where clause
- Entity Framework 6, best strategy to get filtered data from big table with many links to other tables
More Query from same tag
- Using LINQ to select the smallest, most common number in an array
- Make a List of String array from a List of String using LINQ
- Is it possible to get Directory list and filter by owner?
- Convert all T values using LINQ and assign them to an array of different type
- How do I write a LINQ to SQL statement with a custom function that needs the compare the current item context to a passed in value?
- How to pass in a method as an expression using attributes?
- I want to make where clause of LINQ query dynamic
- Why does a Linq Cast<T> operation fail when I have an implicit cast defined?
- InnerJoin vs Contains, which is faster
- How to translate SQL to C#
- use another list items in IN query in existing left join linq query
- How To Sum Tuition of Each Student: What Query?
- Linq - what to do when 'Queries with local collections are not supported'
- Get Top 10 most sold products between date
- How to get all the birthdays of today?
- Why is there an input string exception for a query without where clause?
- How to get value stored in a linq call Expression
- LINQ query returning no results
- SQL to LINQ conversion problems
- Is there any way to use LINQ for MDX queries?
- Convert object to int in Linq Where clause
- Find rows where child collection contains all elements of the list
- C# - XDocument / linq to object
- Convert LINQ written in VB.NET to C#
- count on LINQ union
- Pivot table in Linq
- Alternative Implementation of GetEnumerator() for IEnumerable<T> Wrapper
- Linq: Count value of multiple column
- How does OrderBy in LINQ work (behind the scenes)?
- Issues with LINQ statement with defining an element of a collection