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

Problem with GetSqlQuery and multiline literal strings

1 Answer 36 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
IT
Top achievements
Rank 1
IT asked on 12 Jan 2012, 01:55 AM
considering this example:-

        public IList<Book> Example()
        {
            IList<Book> books = new List<Book>();
 
            string querystring = @"
SELECT
    Name,
    Author
FROM Books
";
 
            IQuery query = factory.Context.Scope.GetSqlQuery(querystring, null, null);
 
            IQueryResult qres = query.Execute();
 
            foreach (object[] item in qres)
            {
                books.Add(new Book()
                {
                    Name = item[0] == null ? "" : item[0].ToString(),
                    Author = item[1] == null ? "" : item[1].ToString()
                });
            }
 
            return books;
        }

it gives me all stores of exceptions such as "Telerik.OpenAccess.RT.sql.SQLException: Could not find stored procedure ''" and "Telerik.OpenAccess.RT.sql.SQLException: Index and length must refer to a location within the string."

if i change querystring so that it is all on a single line, it works fine:-

string querystring = @"SELECT Name, Author FROM Books";

i've tried all sorts of things with the sql to get it to work, but nothing does.

is there a good reason this shouldn't work?

thanks,
aleks

1 Answer, 1 is accepted

Sort by
0
Ralph Waldenmaier
Telerik team
answered on 12 Jan 2012, 01:24 PM
Hi Aleks,

I can reproduce the described behavior which is a bug that will be fixed with the next version.Thank you for reporting this, your Telerik points have been updated.
Since you are working with the context approach, I'd like to recommend calling the ExecuteQuery method of the context. See the documentation under the topic 'How to Execute SQL Statements by Using the Context API Approach'.
Below is an example of how this will look like. 

using (EntitiesModel ctx = new EntitiesModel())
            {
                var sql = @"SELECT TOP 1000 [CategoryID]
      ,[CategoryName]
      ,[Description]
      ,[Picture]
  FROM [NorthwindOA].[dbo].[Categories]";
 
                var result = ctx.ExecuteQuery<Category>(sql, System.Data.CommandType.Text);
            }

I hope this information is useful for you.

All the best,
Ralph
the Telerik team

SP1 for Q3’11 of Telerik OpenAccess ORM is available for download

Tags
Development (API, general questions)
Asked by
IT
Top achievements
Rank 1
Answers by
Ralph Waldenmaier
Telerik team
Share this question
or