This is a migrated thread and some comments may be shown as answers.

ORM GetSqlQuery oddness

5 Answers 55 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kris
Top achievements
Rank 1
Kris asked on 23 Jun 2011, 11:03 PM
I have run into a problem with using the GetSqlQuery() in IObjectScopeProvider.

I have the following code that causes this error:
Query failed: System.NullReferenceException: Object reference not set to an instance of an object.
   at OpenAccessRuntime.Data.VariableLengthStringConverter.Write(DataHolder& data)
   at OpenAccessRuntime.Relational.RelationalQueryResult.SetParameters(RelationalCompiledQuery rcq, PreparedStatement stat, Object[] values)

IQuery q1 = sc.GetSqlQuery(@"SELECT PopulationID, LocationName, Direction, Distance FROM populations WHERE populationid IN  (SELECT populationid FROM populationswrittenreports WHERE  writtenReportID = ?)", typeof(Population), "VARCHAR writtenReportID");
 
         IQueryResult res = q1.Execute(new object[] { reportID });
 
         try
         {
             int count = res.Count;
             return DataDriver.Utilities.ToList<Population>(res.ToList());
         }
         catch
         {
             return new List<Population>();
         }

Now when I change the first two lines to below. the code executes and runs fine. I assume the SELECT IN clause is what is causing the error, seeing as that is the only change. Is there a way to accomplish this without putting all my "complex" sql code into stored procedures?

IQuery q1 = sc.GetSqlQuery(@"SELECT PopulationID, LocationName, Direction, Distance FROM populations ", typeof(Population), null);
 
IQueryResult res = q1.Execute();


thanks

5 Answers, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 29 Jun 2011, 03:01 PM
Hi Kris,

I did try a similar scenario with the standard Northwind database by executing the following query - "select * from Orders where ShipVia in (select ShipperID from Shippers where CompanyName = ? )"
and I could succesfully get the results. Can you provide some information about the table definition, this might provide further insight into the problem. If you can provide a sample solution where I can reproduce the exception this would definitely save us some time.

Looking forward to resolving the issue soon.

Best wishes,
Ady
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
0
Ady
Telerik team
answered on 29 Jun 2011, 03:03 PM
Hello Kris,

I did try a similar scenario with the standard Northwind database by executing the following query - "select * from Orders where ShipVia in (select ShipperID from Shippers where CompanyName = ? )"
and I could succesfully get the results. Can you provide some information about the table definition, this might provide further insight into the problem. If you can provide a sample solution where I can reproduce the exception this would definitely save us some time.

Looking forward to resolving the issue soon.

Best wishes,
Ady
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
0
Kris
Top achievements
Rank 1
answered on 29 Jun 2011, 03:54 PM
I have opened a support ticket (# 438900) and attached a sample app to it. Please take a look and let me know, thanks.
0
Ady
Telerik team
answered on 05 Jul 2011, 05:42 PM
Hello Kris,

 Could we close this thread as I've already answered to your problem via the support thread?

Greetings,
Ady
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Kris
Top achievements
Rank 1
answered on 08 Jul 2011, 04:09 AM
Sure can. I will post your answer in case other developers run into the same issue. Thanks for the help

Answer:
It occurs since the type specified in the query is 'VARCHAR' and the actual column is of type 'uniqueidentifier'. You should replace the 'VARCHAR' with 'GUID' and then it will work

SELECT PopulationID, LocationName, Direction, Distance FROM populations WHERE populationid IN  (SELECT populationid FROM populationswrittenreports WHERE  writtenReportID = ?)", typeof(Population), "GUID writtenReportID"
Tags
General Discussions
Asked by
Kris
Top achievements
Rank 1
Answers by
Ady
Telerik team
Kris
Top achievements
Rank 1
Share this question
or