LinQ Query for selecting multiple data in single row

mnu-nasir

I have following two tables with data.

Table: Pond

Pond_ID              Pond_Owner
 01                    Nasir
 02                    John

Table: Fish

Pond_ID                 Fish_Name
 01                       Koi
 01                       Carp
 02                       Cat Fish
 02                       Gold Fish
 02                       Comet
 02                       Magur

It is noted that Pond_ID field is the primary key in Pond Table and Foreign key in Fish Table. Now I would like to write a LinQ Query to the result like bellow.

Expected Result

Pond_ID              Pond_Owner              Fish_Name
  01                  Nasir                   Koi, Carp
  02                  John                    Cat Fish, Gold Fish, Comet, Magur

So anyone can help me to write this linQ query. Thanks in advance.

Saket

You can perform join operations on LINQ like:

var result = (from p in dbContext.Pond
              join f in dbContext.Fish
              on p.Pond_ID == f.Pond_ID
              select new
              {
              Pond_ID = p.Pond_ID,              
              Pond_Owner = p.Pond_Owner,
              Fish_Name = f.Fish_Name 
}).ToList();

Above query will perform full Join. In case you want to perform left outer join, you can do the same operation using DefaultIfEmpty() as:

  var result = (from p in dbContext.Pond
                  join f in dbContext.Fish                  
                  on p.Pond_ID == f.Pond_ID into group1 
                  from g1 in group1.DefaultIfEmpty()
                  select new
                  {
                  Pond_ID = p.Pond_ID,              
                  Pond_Owner = p.Pond_Owner,
                  Fish_Name = g1.Fish_Name 
    }).ToList();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

LinQ Query for selecting multiple data in single row

From Dev

Selecting multiple values from a single LINQ Query

From Dev

How to update multiple row data in a single query?

From Dev

How to sum a single row with multiple columns in linq query

From Dev

Selecting single row out of multiple ones

From Dev

MYSQL - Selecting multiple rows in a single row

From Dev

Selecting multiple columns with linq query and lambda expression

From Dev

PL/SQL: Selecting multiple variables in a single query

From Dev

Selecting decimal and string anonymous types in single LINQ query that's grouped

From Dev

Multiple row data transformed into single

From Dev

dynamic linq multiple vs single .where query

From Dev

Selecting data as a single row when using select join in mysql

From Dev

Linq to query with multiple row subquery (without join)

From Dev

Linq to Sql query with multiple row subquery

From Dev

displaying multiple rows in single row in sql query

From Dev

Need To Return GroupBy Data With Counts But Selecting Multiple Fields Using LINQ

From Dev

i want fetch the multiple data available in single row-column of table using query how to do that?

From Dev

MySQL query to convert normalized data into single row

From Dev

mysql query to retrieve every single row of data

From Dev

Selecting single row with no unique key

From Dev

Linq query join one table row to another table multiple row

From Dev

Selecting row data as columns

From Dev

sql query to get multiple row value and echo in single row

From Dev

Aggregate data from multiple rows into single row

From Dev

Move data from multiple columns into single row

From Dev

Multiple Rows of Data to Single Row by Conditions

From Dev

Comparing data of single row with multiple rows

From Dev

get single row data into multiple row by calculating cell data

From Dev

Difficulty selecting data from multiple tables with a sub-query

Related Related

  1. 1

    LinQ Query for selecting multiple data in single row

  2. 2

    Selecting multiple values from a single LINQ Query

  3. 3

    How to update multiple row data in a single query?

  4. 4

    How to sum a single row with multiple columns in linq query

  5. 5

    Selecting single row out of multiple ones

  6. 6

    MYSQL - Selecting multiple rows in a single row

  7. 7

    Selecting multiple columns with linq query and lambda expression

  8. 8

    PL/SQL: Selecting multiple variables in a single query

  9. 9

    Selecting decimal and string anonymous types in single LINQ query that's grouped

  10. 10

    Multiple row data transformed into single

  11. 11

    dynamic linq multiple vs single .where query

  12. 12

    Selecting data as a single row when using select join in mysql

  13. 13

    Linq to query with multiple row subquery (without join)

  14. 14

    Linq to Sql query with multiple row subquery

  15. 15

    displaying multiple rows in single row in sql query

  16. 16

    Need To Return GroupBy Data With Counts But Selecting Multiple Fields Using LINQ

  17. 17

    i want fetch the multiple data available in single row-column of table using query how to do that?

  18. 18

    MySQL query to convert normalized data into single row

  19. 19

    mysql query to retrieve every single row of data

  20. 20

    Selecting single row with no unique key

  21. 21

    Linq query join one table row to another table multiple row

  22. 22

    Selecting row data as columns

  23. 23

    sql query to get multiple row value and echo in single row

  24. 24

    Aggregate data from multiple rows into single row

  25. 25

    Move data from multiple columns into single row

  26. 26

    Multiple Rows of Data to Single Row by Conditions

  27. 27

    Comparing data of single row with multiple rows

  28. 28

    get single row data into multiple row by calculating cell data

  29. 29

    Difficulty selecting data from multiple tables with a sub-query

HotTag

Archive