This Forum is ARCHIVE only
For LightSwitch questions,
please use the official forums at:

http://social.msdn.microsoft.com/forums/en-US/lightswitch/threads


Navigation property on preprocess query
Last Post 16 Aug 2013 02:24 AM by gmarazzi01. 6 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Gabriel MarazziUser is Offline
New Member
New Member
Send Private Message
Posts:6
Avatar

--
13 Aug 2013 05:26 AM

    People,

    I have an issue with the preprocess_query method and the navigation properties. I'm developing a web app on Visual Studio Lightswitch 2010.

    I have a screen wich has filters on it. Some of the filter area based on the properties of the entities and others on properties of other entities (related to the main entity)

    Main entity: PedidosDeLicencias

    Field:  Empleado

    Empresa

    Estado

    Licencia

    ElEmpleadosSetItem (relation)

    Related entity:ElEmpleadosSet

    Fields: (only 2, it has mora than 20)

    Empleado

    Puesto

    this is part of my code:

    partial void PedidosDeLicencias_PreprocessQuery(int? Puesto, int? EmpleadoNum, int? EstadoLicenciaNum, short? LicenciaNum, string CCEstructura, int? CCnivel1Num, int? CCnivel2Num, int? CCnivel3Num, int? CCnivel4Num, int? CCnivel5Num, string DDEstructura, int? DDnivel1Num, int? DDnivel2Num, int? DDnivel3Num, int? DDnivel4Num, int? DDnivel5Num, ref IQueryable query) { if (EmpleadoNum.HasValue) { query = query.Where(x => x.Empleado == EmpleadoNum); } if ((Puesto.HasValue) && (Puesto != null)) { //query = query.Where(x => x.ElEmpleadosSetItem.Puesto == Puesto); query = query.Where(x => x.ElEmpleadosSetItem.Puesto == Puesto); }

    if (LicenciaNum.HasValue)
                {

                    query = query.Where(x => x.Inasistencia == LicenciaNum);
                }
                if (EstadoLicenciaNum.HasValue)
                {
                    query = query.Where(x => x.Estado == EstadoLicenciaNum);
                }

    }

    The filter by empleado, licencia and estado works like a charm, but when i want to filter on "Puesto" (Position in english)  it show this error:

    "No se pueden cargar los datos. Compruebe la conexión de red e intente cargarlos de nuevo."

    in english:

    "Unable to load data. Check the network connection and try loading again."

    and the little red cross apears.

    ¿Does anyone know what i'm doing wrong? ¿It is posible to use navigation properties on preprocess query?

    best Regards

    Gabriel

    Gabriel MarazziUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:6
    Avatar

    --
    15 Aug 2013 09:12 PM
    nobody know?

    HELP!!!!!!
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1313
    Avatar

    --
    15 Aug 2013 09:43 PM
    The red X usually means that the query is failing because it can't get to the data.

    For new Visual Studio LightSwitch questions, it is recommended that you use the official Visual Studio LightSwitch Forums at:
    http://social.msdn.microsoft.com/Fo...ightswitch
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    Gabriel MarazziUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:6
    Avatar

    --
    15 Aug 2013 10:51 PM
    yes, but it is posible to add a filter based on a nagivation property and no in a property of the entity?
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1313
    Avatar

    --
    15 Aug 2013 11:05 PM
    It is but I don't know why it is not working in your situation.
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    Gabriel MarazziUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:6
    Avatar

    --
    16 Aug 2013 01:31 AM
    I found some information in the MSDN blog and that I didn't say.

    The two entities are in diferents data sources.

    I think that is the problem.
    Gabriel MarazziUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:6
    Avatar

    --
    16 Aug 2013 02:24 AM
    I solved it!!!!

    this is code:

     partial void PedidosDeLicencias_PreprocessQuery(int? Puesto, int? EmpleadoNum, int? EstadoLicenciaNum, short? LicenciaNum, string CCEstructura, int? CCnivel1Num, int? CCnivel2Num, int? CCnivel3Num, int? CCnivel4Num, int? CCnivel5Num, string DDEstructura, int? DDnivel1Num, int? DDnivel2Num, int? DDnivel3Num, int? DDnivel4Num, int? DDnivel5Num, ref IQueryable<PedidosDeLicenciaSetItem> query)
            {
                IEnumerable<ElEmpleadosSetItem> qEmpleados = this.DataWorkspace.DbEmpleados.ElEmpleadosSet.GetQuery().Execute();
                if (EmpleadoNum.HasValue)
                {
                    query = query.Where(x => x.Empleado == EmpleadoNum);
                }
                if (LicenciaNum != null)
                {
                    query = query.Where(x => x.Inasistencia == LicenciaNum);
                }
                if (EstadoLicenciaNum != null)
                {
                    query = query.Where(x => x.Estado == EstadoLicenciaNum);
                }
                if (Puesto != null)
                {
                    int[] empleadosPuesto = qEmpleados.Where(x => x.Puesto == Puesto).Select(y => y.Empleado).Distinct().ToArray();
                    if (empleadosPuesto.Length > 0)
                    {
                        query = query.Where(x => empleadosPuesto.Contains(x.Empleado));
                    }
                }
    }
    You are not authorized to post a reply.


    Microsoft Visual Studio is a registered trademark of Microsoft Corporation / LightSwitch is a registered trademark of Microsoft Corporation