Asked by:
Equivalent of Group Join in Lambda Expression

Question
-
User-2089506584 posted
Hello,
What will be the equivalent GroupJoin lambda expression in LINQ when I do this.
Dim fruit_salad = (From fruits In _DataContext_Fruits _
Group Join fruitRipe In _DataContext_FruitRipe On fruitRipe.fID Equals fruits.fID Into Group
From fruitty_lecious In Group.DefaultIfEmpty() _
Where fruits.FruitName = "Apple" _
Order By fruits.FruitName Desc _
Select New With { _
.FruitName = fruits.FruitName, _
.FruitCheck = if(fruitty_lecious Is Nothing, False, True) _
}).Where(Function(g) g.FruitCheck.Equals(True))
Lambda not so equivalent from above [:(]
Dim fruit_salad = From fruits In _DataContext_Fruits _
.GroupJoin (???????)
.Where(Function(g) fruits.FruitName = "Apple") _
.GroupBy(Function(g) fruits.FruitName) _
.OrderBy(Function(g) a.Key) _
.Select(Function(g) New With {.Fruit = fruits.FruitName, .FruitCheck = if(fruitty_lecious Is Nothing, False, True)})
I hope you can help me. Thank You.
Tuesday, June 29, 2010 12:39 PM
All replies
-
User-2089506584 posted
I have this C# GroupJoin but I can't convert this to VB.NET correctly [:(]
C#MedicalDataContext db = new MedicalDataContext();
var query = db.Patients.GroupJoin(db.Claims,
p => p.UnqPatientId,
c => c.PatientId,
(Patient, Claims) => new { Patient, Claims });
VB.NETDim db As New MedicalDataContext()
Dim query = db.Patients.GroupJoin(db.Claims, Function(p) p.UnqPatientId, Function(c) c.PatientId, Function(Patient, Claims) New With { _
Patient, _
Claims _
})Wednesday, June 30, 2010 2:11 AM -
User1716267170 posted
Hi imperialx,
I use an online tool to convert the code from C# to VB, and it's exactly like what it looks now. Besides, the above code seems fine. Please show us the exact error message so that we can help you better.
Thnaks.
Friday, July 2, 2010 2:05 AM -
User-2089506584 posted
Hi Wencui,
There is no intellisense for Function(c) c.PatientId, the field PatientId is missing. [:(]
-imperialx
Friday, July 2, 2010 11:26 AM -
User1716267170 posted
There is no intellisense for Function(c) c.PatientId, the field PatientId is missing.
Besides the intellisense, does the code work well? If not, what's the error message in compilation time? Thanks.
Sunday, July 4, 2010 10:20 PM -
User-649019326 posted
I have this C# GroupJoin but I can't convert this to VB.NET correctly
C#MedicalDataContext db = new MedicalDataContext();
var query = db.Patients.GroupJoin(db.Claims,
p => p.UnqPatientId,
c => c.PatientId,
(Patient, Claims) => new { Patient, Claims });
VB.NETDim db As New MedicalDataContext()
Dim query = db.Patients.GroupJoin(db.Claims, Function(p) p.UnqPatientId, Function(c) c.PatientId, Function(Patient, Claims) New With { _
Patient, _
Claims _
})
Tuesday, August 10, 2010 3:46 AM -
User-1591218762 posted
Hi, I need convert a query to lambda, but I don't know. This is the query in VB:
Dim query = From c In Me.ObjectContext.Clientext
Join uc In Me.ObjectContext.UsuarioCliente On c.idCompania Equals uc.idCompania And c.idCliente Equals uc.idCliente
Where c.idCompania = UsuarioActual.Compania.idCompania And uc.Usuario = UsuarioActual.Usuario.Usuario
Select cPlease, help me... Thanks!
Friday, July 8, 2011 8:43 AM