MetadataException

2 posts, 0 answers
  1. Maher
    Maher avatar
    11 posts
    Member since:
    Jul 2012

    Posted 07 Sep 2012 Link to this post

    Hello,

    In the server side, I created the following method:
    public IQueryable<SearchResult> GetHostedPatientsBetween()
            {        
                using (POCEntitiesModel sem = new POCEntitiesModel())
                {
                    string queryString = @"SELECT DISTINCT (DOS.NODOSSIER) AS DOSSIER,
                    DOS.CTE AS CTE,
                    DOS.SIGCOR AS MED,
                    TRIM(MAL.NOM) AS NOM,
                    TRIM(MAL.NOMJF) AS NOMJF,
                    TRIM(TRIM(MAL.PRENOM) || ' ' || TRIM(MAL.PRENOM2)) AS PRENOM,
                    MAL.SEXE AS SEXE,
                    MAL.DATNAI AS DATENAI,
                    TRUNC((MONTHS_BETWEEN(SYSDATE, TO_DATE(MAL.DATNAI, 'yyyymmdd'))) / 12) AS AGE,
                    DOS.PASSDOS AS PASSDOS,
                    MAL.DATDC AS DATEDC,
                    GL.UNITE AS UNITE,
                    GL.NUMETAGE AS ETAGE,
                    GL.NUMCHAMBRE AS CHAMBRE,
                    GL.PLACELIT AS LIT,
                    GL.NUMTEL AS TEL,
                    TO_CHAR(DATEDEB_MOUV, 'dd/mm/yyyy hh24:mm') AS DEBMOUV,
                    TO_CHAR(DATEFIN_MOUV, 'dd/mm/yyyy hh24:mm') AS FINMOUV,
                    TO_CHAR(SYSDATE, 'dd/mm/yyyy hh24:mm') AS DATESYS
                    FROM IM_MALAD MAL, IM_DOSSIER DOS, GLOM_VIEW_SEJOUR GL
                    WHERE MAL.NODOSSIER = DOS.NODOSSIER AND GL.NODOSSIER = DOS.NODOSSIER AND (GL.FLAG_MOUV IS NULL OR GL.FLAG_MOUV = ' ' OR GL.FLAG_MOUV = 'F')
                    AND (GL.FLAGPROVIS_MOUV != 'P' OR GL.FLAGPROVIS_MOUV IS NULL) AND ((GL.DATEDEB_MOUV >= TO_DATE('12/03/2011', 'dd/mm/yyyy') AND
                    GL.DATEDEB_MOUV <= TO_DATE('18/03/2011', 'dd/mm/yyyy')) OR (GL.DATEFIN_MOUV >= TO_DATE('12/03/2011', 'dd/mm/yyyy') AND
                    GL.DATEFIN_MOUV <= TO_DATE('18/03/2011', 'dd/mm/yyyy')) OR (GL.DATEDEB_MOUV <= TO_DATE('18/03/2011', 'dd/mm/yyyy') AND
                    (GL.DATEFIN_MOUV >= TO_DATE('12/03/2011', 'dd/mm/yyyy') OR GL.DATEFIN_MOUV IS NULL)))
                    AND GL.UNITE = 'IEL' AND GL.UNITE != 'MAC'
                    ORDER BY NOM, PRENOM, DOS.NODOSSIER";
                    try
                    {
                        var result = sem.ExecuteQuery<SearchResult>(queryString);
                        return result.AsQueryable();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

            }


    =====> when I run it I get this message : MetadataException was handled by user code: Mapping the result to instances of the class 'POC.Web.SearchResult' failed because the required primary key column 'NODOSSIER' is not present.

  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 12 Sep 2012 Link to this post

    Hello Maher,

     The exception basically means that the primary key of the SearchResult is not returned from your query and thus the object cannot be successfully reconstructed. Please include the primary key in your query(note that the column name should match the property name, if that is not fulfiled you should use the as operator to give an alias to the column so that it matches the property name).
    Once you do that everything should work out as expected.

    All the best,
    Petar
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  3. DevCraft banner
Back to Top