This is a migrated thread and some comments may be shown as answers.
MetadataException
1 Answer 10 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Maher
Top achievements
Rank 2
Maher asked on 07 Sep 2012, 12:52 PM
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.

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 12 Sep 2012, 11:41 AM
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!
Tags
Development (API, general questions)
Asked by
Maher
Top achievements
Rank 2
Answers by
PetarP
Telerik team
Share this question
or