Click here to Skip to main content
16,020,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

little assistance here with my query using dapper, been getting error Message = "ORA-00936: missing expression\n" on my query. I would like to know what am I missing here?

What I have tried:

C#
public class LocationDto  
        {  
            public int LocationId { get; set; }  
            public int RouteId { get; set; }  
            public string StartTime { get; set; }  
            public string Location { get; set; }  
        }  
// Query Below  
    using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))  
                {  
     try {  
                        var x = connection.QueryAsync<LocationDto>("Select ROUTE_ID as RouteId,  SCHEDULE_STOP as Location, START_TIME as StartTime From SCHEDULE WHERE ROUTE_ID = @Id", new { input.RouteId }).Result.ToList();  
      
                    }  
                    catch (Exception ex)  
                    {   
                      
                    }  
    }
Posted
Updated 11-Nov-20 0:43am

1 solution

IIRC, Dapper[^] matches the query parameters based on the name of the property of the anonymous object.

Your query parameter is called Id, but your property is called RouteId.

You can either change the parameter name, or change the property name.
C#
var x = connection.QueryAsync<LocationDto>("Select ROUTE_ID as RouteId,  SCHEDULE_STOP as Location, START_TIME as StartTime From SCHEDULE WHERE ROUTE_ID = @RouteId", new { input.RouteId }).Result.ToList();

// Or:
var x = connection.QueryAsync<LocationDto>("Select ROUTE_ID as RouteId,  SCHEDULE_STOP as Location, START_TIME as StartTime From SCHEDULE WHERE ROUTE_ID = @Id", new { Id = input.RouteId }).Result.ToList();
 
Share this answer
 
Comments
Anele Ngqandu 11-Nov-20 6:49am    
Hi Richard, sadly I tried them both but nothing. Is it maybe because its an oracle query?
Richard Deeming 11-Nov-20 6:55am    
Perhaps - you might need to use : instead of @ for the parameter within the query.
var x = connection.QueryAsync<LocationDto>("Select ROUTE_ID as RouteId,  SCHEDULE_STOP as Location, START_TIME as StartTime From SCHEDULE WHERE ROUTE_ID = :RouteId", new { input.RouteId }).Result.ToList();
Anele Ngqandu 11-Nov-20 7:02am    
That Richard was 100!!Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900