Problem with GetSqlQuery and multiline literal strings

Thread is closed for posting
2 posts, 0 answers
  1. IT
    IT avatar
    41 posts
    Member since:
    Jan 2010

    Posted 11 Jan 2012 Link to this post

    considering this example:-

            public IList<Book> Example()
                IList<Book> books = new List<Book>();
                string querystring = @"
    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?

  2. Ralph Waldenmaier
    Ralph Waldenmaier avatar
    202 posts

    Posted 12 Jan 2012 Link to this post

    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]
      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,
    the Telerik team

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

Back to Top