I have 3 tables (Master, Imagen, Linea) were:
Master
public virtual int Id { get; private set; }
public virtual Imagen imagen { get; set; }
Imagen
public virtual int Id { get; private set; }
public virtual Linea linea { get; set; }
Linea
public virtual int Id { get; private set; }
public virtual String Nombre { get; set; }
I need a query like this:
SELECT * FROM dbo.Master
INNER JOIN dbo.Imagen ON dbo.Master.imagen_id = dbo.Imagen.Id
INNER JOIN dbo.Linea ON dbo.Imagen.linea_id = dbo.Linea.Id
WHERE dbo.Linea_Id = 5
But I dont know how to tell Fluent Nhibernate to create this query using the automapper. So far I've tried this:
ICriteria c = session.CreateCriteria(typeof(Master))
.CreateAlias("dbo.Imagen", "img", JoinType.InnerJoin)
.Add(Restrictions.Eq("img.linea_id", id_linea));
return c.List<Master>();
But I get this error: could not resolve property: dbo of: ImageManager.Model.Entity.Master
Any ideas on how to do a Inner Join? Thanks in advance
For a start I would get rid of the dbo from dbo.Imagen. Using the ICriteria interface you need to think in-terms of objects, not database tables, even though there may be a one to one mapping of object to table and properties to columns.
EDIT:
another option would be to use the QueryOver Lambda syntax.
var list = session.QueryOver<Master>()
.JoinQueryOver(master => master.imagen)
.Where(imagen => imagen.linea.Id == 5)
.List();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With