- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
SQL to LLBL conversion help
Posts
Posts: 2
Joined: 21-Dec-2005
Joined: 21-Dec-2005
# Posted on: 21-Dec-2005 19:12:11
hello. i need to execute the following query in mysql:
select
Boleto.IdBoleto,
Lugar.Nombre 'Lugar',
Seccion.Nombre 'Seccion',
Fila.Nombre 'Fila',
Asiento.NumeroDeAsiento 'Asiento',
Evento.Nombre 'Evento',
Funcion.Nombre 'Funcion',
CategoriaDePrecio.Nombre 'TipoDePrecio',
CategoriaDePrecio.PrecioInicial 'Precio'
from Boleto
inner join Lugar on Boleto.IdLugar = Lugar.IdLugar
inner join Seccion on Boleto.IdSeccion = Seccion.IdSeccion
inner join Fila on Boleto.IdFila = Fila.IdFila
inner join Asiento on Boleto.IdAsiento = Asiento.IdAsiento
inner join Evento on Boleto.IdEvento = Evento.IdEvento
inner join Funcion on Boleto.IdFuncion = Funcion.IdFuncion
inner join CategoriaDePrecio on Boleto.IdCategoriaDePrecio = CategoriaDePrecio.IdCategoriaDePrecio
inner join Orden on Boleto.IdOrden = Orden.IdOrden
where Orden.IdOrden = 1 and
Orden.IdCuenta = 1 and
(Orden.FechaExpiracionReserva is null or now() < Orden.FechaExpiracionReserva)
and i'm doing the following code
EntityRelation boletoFila = new EntityRelation(RelationType.OneToOne);
boletoFila.StartEntityIsPkSide = true;
boletoFila.AddEntityFieldPair(EntityFieldFactory.Create(BoletoFieldIndex.IdFactura),
EntityFieldFactory.Create(FilaFieldIndex.IdFila));
EntityRelation boletoAsiento = new EntityRelation(RelationType.OneToOne);
boletoAsiento.StartEntityIsPkSide = true;
boletoAsiento.AddEntityFieldPair(EntityFieldFactory.Create(BoletoFieldIndex.IdAsiento),
EntityFieldFactory.Create(AsientoFieldIndex.IdAsiento));
EntityRelation boletoOrden = new EntityRelation(RelationType.OneToOne);
boletoOrden.StartEntityIsPkSide = true;
boletoOrden.AddEntityFieldPair(EntityFieldFactory.Create(BoletoFieldIndex.IdOrden),
EntityFieldFactory.Create(OrdenFieldIndex.IdOrden));
EntityRelation boletoCategoriaDePrecio = new EntityRelation(RelationType.OneToOne);
boletoCategoriaDePrecio.StartEntityIsPkSide = true;
boletoCategoriaDePrecio.AddEntityFieldPair(EntityFieldFactory.Create(BoletoFieldIndex.IdCategoriaDePrecio),
EntityFieldFactory.Create(CategoriaDePrecioFieldIndex.IdCategoriaDePrecio));
EntityRelation boletoEvento = new EntityRelation(RelationType.OneToOne);
boletoEvento.StartEntityIsPkSide = true;
boletoEvento.AddEntityFieldPair(EntityFieldFactory.Create(BoletoFieldIndex.IdEvento),
EntityFieldFactory.Create(EventoFieldIndex.IdEvento));
EntityRelation boletoFuncion = new EntityRelation(RelationType.OneToOne);
boletoFuncion.StartEntityIsPkSide = true;
boletoFuncion.AddEntityFieldPair(EntityFieldFactory.Create(BoletoFieldIndex.IdFuncion),
EntityFieldFactory.Create(FuncionFieldIndex.IdFuncion));
EntityRelation boletoSeccion = new EntityRelation(RelationType.OneToOne);
boletoSeccion.StartEntityIsPkSide = true;
boletoSeccion.AddEntityFieldPair(EntityFieldFactory.Create(BoletoFieldIndex.IdSeccion),
EntityFieldFactory.Create(SeccionFieldIndex.IdSeccion));
RelationPredicateBucket rpb = new RelationPredicateBucket();
rpb.Relations.Add(boletoFila, JoinHint.Inner);
rpb.Relations.Add(boletoAsiento, JoinHint.Inner);
rpb.Relations.Add(boletoOrden, JoinHint.Inner);
rpb.Relations.Add(boletoCategoriaDePrecio, JoinHint.Inner);
rpb.Relations.Add(boletoEvento, JoinHint.Inner);
rpb.Relations.Add(boletoFuncion, JoinHint.Inner);
rpb.Relations.Add(boletoSeccion, JoinHint.Inner);
rpb.PredicateExpression.Add(PredicateFactory.CompareExpression(
OrdenFieldIndex.IdEstadoDeOrden,
ComparisonOperator.Equal, idEstadoDeOrden));
rpb.PredicateExpression.AddWithAnd(PredicateFactory.CompareExpression(
OrdenFieldIndex.IdOrden,
ComparisonOperator.Equal, idOrden));
rpb.PredicateExpression.AddWithAnd(PredicateFactory.CompareExpression(
OrdenFieldIndex.IdCuenta,
ComparisonOperator.Equal, idCuenta));
PredicateExpression pe = new PredicateExpression();
pe.Add(PredicateFactory.CompareNull(
OrdenFieldIndex.FechaExpiracionReserva));
pe.AddWithOr(PredicateFactory.CompareExpression(
OrdenFieldIndex.FechaExpiracionReserva,
ComparisonOperator.GreaterThan, DateTime.Now));
rpb.PredicateExpression.AddWithAnd(pe);
ResultsetFields fields = new ResultsetFields(6);
fields.DefineField(BoletoFieldIndex.IdBoleto, 0, "IdBoleto");
fields.DefineField(LugarFieldIndex.Nombre, 1, "Lugar");
fields.DefineField(SeccionFieldIndex.Nombre, 2, "Seccion");
fields.DefineField(FilaFieldIndex.Nombre, 3, "Fila");
fields.DefineField(AsientoFieldIndex.NumeroDeAsiento, 4, "Asiento");
fields.DefineField(EventoFieldIndex.Nombre, 5, "Evento");
fields.DefineField(FuncionFieldIndex.Nombre, 6, "Funcion");
fields.DefineField(CategoriaDePrecioFieldIndex.Nombre, 7, "TipoDePrecio");
fields.DefineField(CategoriaDePrecioFieldIndex.PrecioInicial, 8, "Precio");
System.Data.DataTable dt = new System.Data.DataTable();
adapter.FetchTypedList(fields, dt, rpb);
is it ok?
Posts: 934
Joined: 12-Feb-2004
Joined: 12-Feb-2004
# Posted on: 22-Dec-2005 02:34:58
First I would say that you need to include more fields in your typedlist declaration. You have
ResultsetFields fields = new ResultsetFields(6);
and it should be
ResultsetFields fields = new ResultsetFields(9);
You also have
rpb.PredicateExpression.Add(PredicateFactory.CompareExpression( OrdenFieldIndex.IdEstadoDeOrden, ComparisonOperator.Equal, idEstadoDeOrden));
but you didn't include this requirement in the query and it may be causing behavior that you do not desire. Is there anything not working with the query that you are curious about?