0

I have the following tables:

Table Material
Id
Table Zone
Id
Table MaterialZone
Id
Material_Id
Zone_Id
Price


Edit
What I need is to have the MaterialZone (whit the current Zone) in the Material object, I dont know if I can solve it by mapping or by Query, because the relational "Id" its in the MaterialZone table.

The Maps

MapMaterialZone()
    {
        Id(x => x.Id).GeneratedBy.Identity();
        ///Properties
        References(x => x.Material).Column("material_id");
        References(x => x.Zone).Column("zone_id");
    }

MapZona()
    {
        Id(x => x.Id).GeneratedBy.Identity();
        ///Properties
    }
MapMaterial()
    {
        Id(x => x.Id).GeneratedBy.Identity();
        ///Properties
        //HasMany(x => x.ListMaterialZone);
        //HasOne(x => x.IndividualMaterialZone).PropertyRef(MaterialZona => MaterialZona.Material);
    }

I first tried to add and map The IList<"MaterialZone">, and the MaterialZone property searches in the list and returns the one with the current Zone, but the Query and the controls got too slow. (Im working with Access an ComponentOne)

I have tried to solve this from mapping and Querys but I havent had much luck. I have medium experience in NHibernate and Mapping and little experience in QueryOver and ICriteria

Im open to all solutions (but unfortunatelly Access has to stay) Thanks.

leomcpugo
  • 35
  • 8
  • 1
    Hi, you didn't actually ask a question. Could you please edit and ask a question. Also, it would be helpful if you copy and paste your mapping files and classes as well. The more information you give up front, the easier it is for someone to answer your question. Thanks. – Randy Burden Apr 09 '13 at 23:18
  • True true, I was so busy explaining I didnt ask the question, sorry its my first time, I will edit the post – leomcpugo Apr 11 '13 at 03:44

1 Answers1

0

I´ve found a solution, my mapping

MaterialMap
HasOne(x => x.MaterialZona).PropertyRef(materialZona => materialZona.Material);

and the final QueryOver

ISession session = GetSession();
Zona zonaPredeterminada = GetDefaultZone();
Material materialAlias = null;
MaterialZona materialZonaAlias = null;

return session.QueryOver<Material>(() => materialAlias)
    .JoinQueryOver(mat => mat.MaterialZona, () => materialZonaAlias)
    .Where(mZ => mZ.Zona.Id == zonaPredeterminada.Id)
    .And(mZ => mZ.Material.Id == materialAlias.Id)
    .List();
leomcpugo
  • 35
  • 8