LINQ. Inner Join.

S

shapper

Hello,

I have 2 tables:
[A] > Aid, Aname ...
> 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
 
P

Patrice

I believe I saw this discussed at
http://weblogs.asp.net/scottgu/archive/tags/LINQ/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...
 
P

Patrice

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 said:
I believe I saw this discussed at
http://weblogs.asp.net/scottgu/archive/tags/LINQ/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 said:
Hello,

I have 2 tables:
[A] > Aid, Aname ...
> 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

 
S

shapper

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.

I believe I saw this discussed at
http://weblogs.asp.net/scottgu/archive/tags/LINQ/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...
shapper said:
Hello,
I have 2 tables:
[A] > Aid, Aname ...
> 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=r...McUfOL924zdAQ2aQg&sig2=PQx33tW7Oc5GF4UFKa22dQ

It is a LINQ standard query operators released by Microsoft.

Thanks,
Miguel
 
P

Patrice

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]
[cut]

I found a link that might interest you:
http://www.google.com/url?sa=t&ct=r...McUfOL924zdAQ2aQg&sig2=PQx33tW7Oc5GF4UFKa22dQ

It is a LINQ standard query operators released by Microsoft.

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top