I have the following class:-
public class ContactsDetails
{
public IEnumerable<AaaUserContactInfo> Info { get; set; }
}
where AaaUserContactInfo has two foreign keys refering to other tables:-
public partial class AaaUserContactInfo
{
public long USER_ID { get; set; }
public long CONTACTINFO_ID { get; set; }
public string desc { get; set; }
public virtual AaaContactInfo AaaContactInfo { get; set; }
public virtual AaaUser AaaUser { get; set; }
}
Now i have the following class which intiate a new ContactDetails object:-
public ActionResult CustomersDetails(long[] OrganizationIds)
{
if (OrganizationIds == null)
{
return RedirectToAction("customer", new { isError = true });
}
else
{
var ContactsDetails = new ContactsDetails
{
Info = r.getcontactinfo(OrganizationIds)
};
}
return View();
}
now i need to return all the AaaUserContactInfo object which have their emails Ids containing part of the organization name,, something similar to:-
public IEnumerable<AaaUserContactInfo> getcontactinfo(long[] Organizationid)
{
var result = ((from uci in entities.AaaUserContactInfoes
join ci in entities.AaaContactInfoes on uci.CONTACTINFO_ID equals ci.CONTACTINFO_ID
where ci.EMAILID.ToString() == // contains any organization name in their emailIds ,, where i can get the organization name using sonthing similar to var orgname = entities.SDOrganizations.Where(a => a.ORG_ID == OrganizationIds[i]).FirstOrDefault().NAME;
select uci)) ;
return result;
}
Can you try to use next query? I don’t know what you want to do if
FirstOrDefault()in your example return null. In my case no exception will be throws, but not records will be returned. Please note about the details of the implementation and if it worked at all.EDIT: updated an answer to handle many organizations selected on the basis of
Organizationid. Thenentities.AaaContactInfoesare selected ifEMAILIDis contained in name field of at least one ogranization.NOTE: i have renamed some arguments used only in the method scope, just to make code more readable.