By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,945 Members | 1,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,945 IT Pros & Developers. It's quick & easy.

LINQ. Inner Join.

P: n/a
Hello,

I have 2 tables:
[A] Aid, Aname ...
[b] Bid, Aid, Bname ...

I need to get the records in B given a Bname and a Aname. I think I
should use Inner Join.

I wrote the following code:

Dim Bs = From a In db.A _
Join b In db.B _
On a.Aid Equals b.Aid _
Where a.Aname = AName And b.Bname = BName

This is not working.
What am I doing wrong?
And is there Inner Join in LINQ?

Thanks,
Miguel

Oct 17 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I believe I saw this discussed at
http://weblogs.asp.net/scottgu/archi...Q/default.aspx. This is
called a group join.

I'm starting myself to check what LINQ could do for us. My understanding for
now is :

- keep in mind that is "looks like" SQL but this is not SQL so you re not
always using the constructs you are used to but more .NET centrics
constructions (such as IN vs MyList.Contains)

- similarly inner join, left join are done with something called "group
join" that uses some kind of weird syntax. I'm not sure I fully read the
paper yet but I believe the idea is that using the usual join would prevent
using structured objects. With group join you could perhaps be able to
expose the resultset as a collection as well as inner collections for each
rows.

As I said I'm still very new so you may want to check the article by
yourself (and keep us informed of your findings). I'll try to tell you if I
can get back at this as I'm also interested to check this more deeply than
my first read...

--
Patrice
"shapper" <md*****@gmail.coma écrit dans le message de news:
11*********************@v29g2000prd.googlegroups.c om...
Hello,

I have 2 tables:
[A] Aid, Aname ...
[b] Bid, Aid, Bname ...

I need to get the records in B given a Bname and a Aname. I think I
should use Inner Join.

I wrote the following code:

Dim Bs = From a In db.A _
Join b In db.B _
On a.Aid Equals b.Aid _
Where a.Aname = AName And b.Bname = BName

This is not working.
What am I doing wrong?
And is there Inner Join in LINQ?

Thanks,
Miguel

Oct 17 '07 #2

P: n/a
BTW what is the error you get ? If you really want just a join, it should
work as this construct is part of the query language.

"Patrice" <http://www.chez.com/scribe/a écrit dans le message de news:
eU**************@TK2MSFTNGP05.phx.gbl...
>I believe I saw this discussed at
http://weblogs.asp.net/scottgu/archi...Q/default.aspx. This is
called a group join.

I'm starting myself to check what LINQ could do for us. My understanding
for now is :

- keep in mind that is "looks like" SQL but this is not SQL so you re not
always using the constructs you are used to but more .NET centrics
constructions (such as IN vs MyList.Contains)

- similarly inner join, left join are done with something called "group
join" that uses some kind of weird syntax. I'm not sure I fully read the
paper yet but I believe the idea is that using the usual join would
prevent using structured objects. With group join you could perhaps be
able to expose the resultset as a collection as well as inner collections
for each rows.

As I said I'm still very new so you may want to check the article by
yourself (and keep us informed of your findings). I'll try to tell you if
I can get back at this as I'm also interested to check this more deeply
than my first read...

--
Patrice
"shapper" <md*****@gmail.coma écrit dans le message de news:
11*********************@v29g2000prd.googlegroups.c om...
>Hello,

I have 2 tables:
[A] Aid, Aname ...
[b] Bid, Aid, Bname ...

I need to get the records in B given a Bname and a Aname. I think I
should use Inner Join.

I wrote the following code:

Dim Bs = From a In db.A _
Join b In db.B _
On a.Aid Equals b.Aid _
Where a.Aname = AName And b.Bname = BName

This is not working.
What am I doing wrong?
And is there Inner Join in LINQ?

Thanks,
Miguel


Oct 17 '07 #3

P: n/a
On Oct 17, 5:18 pm, "Patrice" <http://www.chez.com/scribe/wrote:
BTW what is the error you get ? If you really want just a join, it should
work as this construct is part of the query language.

"Patrice" <http://www.chez.com/scribe/a écrit dans le message de news:
eUguIPNEIHA.1...@TK2MSFTNGP05.phx.gbl...
I believe I saw this discussed at
http://weblogs.asp.net/scottgu/archi...Q/default.aspx. This is
called a group join.
I'm starting myself to check what LINQ could do for us. My understanding
for now is :
- keep in mind that is "looks like" SQL but this is not SQL so you re not
always using the constructs you are used to but more .NET centrics
constructions (such as IN vs MyList.Contains)
- similarly inner join, left join are done with something called "group
join" that uses some kind of weird syntax. I'm not sure I fully read the
paper yet but I believe the idea is that using the usual join would
prevent using structured objects. With group join you could perhaps be
able to expose the resultset as a collection as well as inner collections
for each rows.
As I said I'm still very new so you may want to check the article by
yourself (and keep us informed of your findings). I'll try to tell you if
I can get back at this as I'm also interested to check this more deeply
than my first read...
--
Patrice
"shapper" <mdmo...@gmail.coma écrit dans le message de news:
1192632529.550509.36...@v29g2000prd.googlegroups.c om...
Hello,
I have 2 tables:
[A] Aid, Aname ...
[b] Bid, Aid, Bname ...
I need to get the records in B given a Bname and a Aname. I think I
should use Inner Join.
I wrote the following code:
Dim Bs = From a In db.A _
Join b In db.B _
On a.Aid Equals b.Aid _
Where a.Aname = AName And b.Bname = BName
This is not working.
What am I doing wrong?
And is there Inner Join in LINQ?
Thanks,
Miguel
Hi,

I have the following:

' Create data context
Dim db As New BoxesDataContext

' Select cards
Dim cards = From b In db.Boxes _
Join c In db.Cards On b.BoxId Equals c.BoxID _
Where b.Name = Me.BoxName And c.Name = Me.CardName _
Select New With {c.Face}

I think now it is group. However, I am not sure if Join is the way to
go.
As you said there is also group join.

I found a link that might interest you:
http://www.google.com/url?sa=t&ct=re...Oc5GF4UFKa22dQ

It is a LINQ standard query operators released by Microsoft.

Thanks,
Miguel

Oct 18 '07 #4

P: n/a
Let's restart perhaps from the beginning ? My understanding is that a inner
join would be enough for you but for now we don't know what ti s the problme
you get with this.

What doesn't work ? what is the message you get ?

Note that you are linking on Aid but you have also two distinct criterias on
a name property for both A and B (why on both if you also have a join, are
you sure AName and BName combination is part of the result set ?). If the
problem is that the query doesn't return anything could it be the problem ?
You can also use the log property or a profiler to get the generated SQL.

Thanks for the link. I found
http://msdn2.microsoft.com/en-us/library/bb394939.aspx and I've been able to
return a result for each secretary and a collection for each employees they
are are working for, using a group join (still not sure though I really have
to use a group join though)...

[cut]
I wrote the following code:
Dim Bs = From a In db.A _
Join b In db.B _
On a.Aid Equals b.Aid _
Where a.Aname = AName And b.Bname = BName
[cut]

I found a link that might interest you:
http://www.google.com/url?sa=t&ct=re...Oc5GF4UFKa22dQ

It is a LINQ standard query operators released by Microsoft.

Thanks,
Miguel
Oct 19 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.