简体   繁体   中英

SQL translated into fluent Nhibernate => joining with static values

I am trying to turn this sql statement into a fluent nhibernate mapping :

select *
from Project p
inner join ProjectData pd on p.Project = pd.Project
inner join ProjectCompany pc on p.Project = pc.Project and pc.InitComp = 'Yes' and pc.Company = pd.LogComp
inner join ProjectCustomer cust on cust.id = pd.custid

I'm facing a number of problems for getting this statement into a single entity(all joins are a 1 on 1 relationship).
I am aware that a single view would solve my issues but alas i don't have the privileges to create one.

Currently my code looks like this

Table("Project");
Id(p=> p.Number);
Join("ProjectData", j =>
{
    j.Fetch.Join();
    j.KeyColumn("Project");
    j.Map(pd => pd.Customer);
});
Map(p => p.Complexity);

The problems i am facing are :

  • How do i create a hard coded filter (pc.InitComp = 'Yes')
  • How do i join with 2 statements(p.project = pc.Project and pc.Company = pd.LogComp
  • How do i join from a joined table rather then the base one?(ProjectCustomer joins on ProjectData)

A lot of questions for something so trivial in sql but i can't seem to find a simple answer on the internet other then create a view.

I ended up with a raw sql query and using a datareader to manually fill my object.
This worked cause i only needed to read from a table and not write.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM