I'm attemping from C# this LINQ expression, but it does not seem to work
C#
var v = (from a in dc.ChatPrivateMessageMasters
join b in dc.ChatPrivateMessageDetails on a.EmailID equals b.MasterEmailID into cc
from c in cc
where (c.MasterEmailID.Equals(fromid) && c.ChatToEmailID.Equals(toid)) || (c.MasterEmailID.Equals(toid) && c.ChatToEmailID.Equals(fromid))
orderby c.ID descending
select new
{
UserName = a.UserName,
Message = c.Message,
ID = c.ID
}).Take(take).ToList();
VB
Dim v = (From a In dc.ChatPrivateMessageMasters _
Join b In dc.ChatPrivateMessageDetails On a.EmailID Equals b.MasterEmailID _
Into cc _
From c In cc Where (c.MasterEmailID.Equals(fromid) AndAlso c.ChatToEmailID.Equals(toid)) OrElse (c.MasterEmailID.Equals(toid) AndAlso c.ChatToEmailID.Equals(fromid)) _
Order By c.ID Descending _
Select New With { _
.UserName = a.UserName, _
.Message = c.Message, _
.ID = c.ID _
}).Take(take).ToList()
I received an error from 'Into' with message: ')' expected
Any idea?
For starters, you don't need the group join (the into
part of your join
clause), considering you flatten it immediately (and don't do a left outer join for example).
Your C# query can simply be:
var query =
(from m in dc.ChatPrivateMessageMasters
join d in dc.ChatPrivateMessageDetails on m.EmailID equals d.MasterEmailID
where (d.MasterEmailID == fromid && d.ChatToEmailID == toid)
|| (d.MasterEmailID == toid && d.ChatToEmailID == fromid)
orderby d.ID descending
select new
{
m.UserName,
d.Message,
d.ID
}).Take(take).ToList();
And the VB.net equivalent of that is:
Dim query =
(From m In dc.ChatPrivateMessageMasters
Join d In dc.ChatPrivateMessageDetails On m.EmailID Equals d.MasterEmailID
Where (d.MasterEmailID = fromid AndAlso d.ChatToEmailID = toid)
OrElse (d.MasterEmailID = toid AndAlso d.ChatToEmailID = fromid)
Order By d.ID Descending
Select m.UserName, d.Message, d.ID
Take take).ToList
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.