我需要获取与给定业务和给定联系人代码相关的联系人。联系人可以有多个联系人代码。
这就像我能够得到的一样 - 任何帮助都值得赞赏......
int bid = 10;
var sendto = from businesscontact in db.businesscontacts.Where(bus => bus.businessid == bid).Include(bc => bc.contact where contact.contactscontactcodes.contactcodesid.Contains(55)) select r.email;
这是......之后的等效t-sql ...
SELECT contacts.email
FROM businesscontacts
INNER JOIN contacts ON businesscontacts.contactsid = contacts.contactsid
INNER JOIN contactscontactcodes ON contacts.contactsid = contactscontactcodes.contactsid
where contactscontactcodes.contactcodesid = @cid
AND businesscontacts.businessid = @bid
答案 0 :(得分:1)
using(EntityClass entities = new EntityClass())
{
var email =
(from biz in entities.BusinessContacts
where biz.businessid = bid
from codes in entities.ContactsContactCodes
where codes.contactcodesid = cid
from c in entites.Contacts
where c.contactsid == codes.contactsid && c.contactsid == biz.contactsid
select c.email).FirstOrDefault();
}
答案 1 :(得分:0)
int cid = 1;
int bid = 2;
var sendto = from businesscontact in db.businesscontacts
join contacts in db.contacts
on businesscontact.contactsid equals contacts.contactid
join contactscontactcodes in db.contactscontactcodes
on contacts.contactsid equals contactscontactcodes.contactsid
where contactscontactcodes.contactcodesid = cid
&& businesscontacts.businessid = bid
select contact.email;