/** * SELECT a.* FROM Ads AS a * INNER JOIN Contacts AS c ON a.Contact = c.Id * WHERE c.Company = ( * SELECT Company * FROM Contacts * WHERE Email = '..' * ) * ORDER BY a.PublishedOn DESC; */
/**
* Objective: To retreive all Ad's that belong to a
* given Company.
* To get the Company you use Contact.Email and that Contact's Company.
*/
class Ad
{
public virtual int Id { get; set; }
public virtual Contact Contact { get; set; }
}
class Contact
{
public virtual int Id { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection<Ad> CreatedAds { get; set; }
public virtual string Email { get; set; }
}
class Company
{
public virtual int Id { get; set; }
public virtual ICollection<Contact> Contacts { get; set; }
}
Basically, how can I select all the Ads from a given Company?
Preferably in one query, so I can supply only the current Contacts Email and
get all the other Contacts Ads in the same Company.
Contact contact = session.QueryOver(x => x.Email ==
"[email protected]").SingleOrDefault();
IEnumerable<Contact> contacts = contact.Company.Contacts;
IEnumerable<Ad> ads = contacts.SelectMany(x => x.CreatedAds);
foreach(Ad ad in ads)
{
}
Med vänliga hälsningar,
Kim Johansson
Industritorget Sweden AB
Söndrumsvägen 29
302 39 Halmstad
tel: 035 - 260 32 00
fax: 035 - 12 24 83
epost: [email protected]<mailto:[email protected]>
webb: http://www.industritorget.se
[cid:[email protected]]<http://www.industritorget.se/>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.
<<inline: image001.jpg>>
