2 Replies - 7135 Views - Last Post: 04 April 2013 - 02:14 AM

#1 rapo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 27-November 08

Extract data from two tables using LINQ

Posted 03 April 2013 - 01:01 PM

Hello,
I have a GridView which I want to filled with data from 2 tables from a database. The scenario is like this:

- I have a LINQ QUERY(QUERY1) that gets data(COL1,COL2,COL3) from TABLE1 if COND1 is fulfilled.
- with the results from QUERY1 I want to get data from TABLE2
- I have QUERY2 on TABLE2 like this if (COL1(QUERY1) == value and COL2(QUERY) == value) return something as COL4. For each row returned by QUERY1 is made QUERY2 request. If QUERY2 returns a row I want to have a structure like this:

COL1(Data) COL2(Data) COL3(Data) YES

If QUERY2 return 0 rows I want to have in the same structure
COL1(Data) COL2(Data) COL(Data)3 NO

So the IQueryable structure could look like this:

COL1 COL2 COL3 COL4
val1 val2 val3 NO
val1 val2 val3 YES
val1 val2 val3 NO
....




It's possible to do this with a LINQ command ?

Is This A Good Question/Topic? 0
  • +

Replies To: Extract data from two tables using LINQ

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3190
  • View blog
  • Posts: 10,677
  • Joined: 12-December 12

Re: Extract data from two tables using LINQ

Posted 03 April 2013 - 01:44 PM

I suspect that this is possible, although I haven't investigated. However, are you sure that you don't just need to use a table-join (or a sub-query) to obtain data from both tables?
Was This Post Helpful? 0
  • +
  • -

#3 rapo  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 27-November 08

Re: Extract data from two tables using LINQ

Posted 04 April 2013 - 02:14 AM

My limitations are:
- I can't modify the database, because it's already used.
- I want to obtain a IQueryable structure because this is the type accepted by the paging system.

If this could be implemented in other way no problem but I don't know yet how it's better.

I've made until now like this:

For each entry obtained with QUERY1 I've made QUERY2 and depending on results of QUERY2 I've inserted data in a new DataTable, I've converted the datatable as IQueryable and it's done. The problem is that when I'm doing the binding with the GridView I need to make another datatable to get the table header. Maybe I'm doing it wrong but this is working.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1