3 Replies - 13379 Views - Last Post: 12 January 2011 - 08:08 AM Rate Topic: -----

#1 Guest_HopeToBelieveIn*


Reputation:

querying in fluent NHibernate

Posted 12 January 2011 - 06:40 AM

I'm using Fluent NHibernate.
Iv got 3 classes
public class employee
{
public virtual int Id { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Address { get; set; }
public virtual post Post { get; set; }
public virtual firm Firm { get; set; }
public virtual DateTime BirthDate { get; set; }
}
public class firm
{
public virtual int Id { get; set; }
public virtual string FirmName { get; set; }
public virtual int Inn { get; set; }
public virtual int Kpp { get; set; }
public virtual string FirmAddress { get; set; }
public virtual DateTime RegDate { get; set; }
}

public class post
{
public virtual int Id { get; set; }
public virtual string PostName { get; set; }
}


I want to select FirstName, LastName from table employee; PostName from table post and FirmName from table firm were employee.Post_id, employee.Firm_id are the same as in tables post, firm.

Native sql query:
Select e.FirstName, e.LastName, p.PostName, f.FirmName from employee e, post p, firm f WHERE e.Post_id=p.Id AND e.Firm_id=f.Id;



my NHibernate queryes versions:
1)
IQuery q2 = session.CreateQuery("from employee e, post p, firm f WHERE e.Post=p.Id AND e.Firm=f.Id;");
IList<object> emps = q2.List<object>();

2)
IQuery q = session.CreateQuery("SELECT e.Id, e.FirstName, e.LastName, p.PostName, 
f.FirmName from employee e, post p, firm f WHERE e.post_id=p.Id AND e.firm_id=f.Id;");

IList<object> emps = q.List<object>();
3)
IList<object> emps = session.CreateSQLQuery("SELECT {e}.Id AS {e.Id},{e}.FirstName AS 
{e.FirstName}, {e}.LastName AS {e.LastName}, {p}.PostName AS {p.PostName}, {f}.FirmName AS 
{f.FirmName} from employee {e}, post {p}, firm {f} WHERE {e}.Post={p}.Id AND {e}.Firm=
{f}.Id;").List<object>();


none of query is not working.

What should i fix?

Is This A Good Question/Topic? 0

Replies To: querying in fluent NHibernate

#2 Guest_HopeToBelieveIn*


Reputation:

Re: querying in fluent NHibernate

Posted 12 January 2011 - 07:30 AM

I solved this problem. How should i delete this topic?
Was This Post Helpful? 0

#3 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4577
  • View blog
  • Posts: 8,019
  • Joined: 08-June 10

Re: querying in fluent NHibernate

Posted 12 January 2011 - 07:46 AM

We don't delete topics here. But if you wouldn't mind posting your solution, in case someone else comes along with a similar problem?
Was This Post Helpful? 0
  • +
  • -

#4 Guest_HopeToBelieveIn*


Reputation:

Re: querying in fluent NHibernate

Posted 12 January 2011 - 08:08 AM

Final query
IQuery q =session.CreateQuery("Select e.FirstName, e.LastName, p.PostName, f.FirmName from employee e, post p, firm f WHERE e.Post=p AND e.Firm=f");
IList<object> emps = q.List<object>();



I needed to compare complete post and firm classes. Not only their Ids.
Was This Post Helpful? 0

Page 1 of 1