Openaccesscontext GetAll(of T) error

6 posts, 0 answers
  1. Preet Kumar
    Preet Kumar avatar
    6 posts
    Member since:
    Mar 2007

    Posted 05 Feb 2014 Link to this post

    Hello,

    I have just started learning Telerik ORM (was using LLBLGen earlier).

    I am trying to join 2 tables in following query and I get an error. However, individually, they run fine. Can you shed some insight on this?

    Dim context = ContextFactory.GetContextPerRequest          
     
    Dim query = (From c In context.GetAll(Of FaqCategory)(), i In context.GetAll(Of FaqItem)()
                  Where c.Id = i.CategoryId
                  Order By c.OrderNo, i.OrderNo
                  Select c.CategoryName, i.Question, i.Answer).ToList



    I get following error

    An exception occured during the execution of 'Extent<Saadhana.DataLayer.FaqCategory>().SelectMany(c => Convert(value(Saadhana.BusinessLayer.DBHelperClasses.FaqHelper+_Closure$__1).$VB$Local_context.GetAll()), (c, i) => new VB$AnonymousType_0`2(c = c, i = i)).Where($VB$It => ($VB$It.c.Id == $VB$It.i.CategoryId)).OrderBy($VB$It => $VB$It.c.OrderNo).ThenBy($VB$It => $VB$It.i.OrderNo).Select($VB$It => new VB$AnonymousType_1`3(CategoryName = $VB$It.c.CategoryName, Question = $VB$It.i.Question, Answer = $VB$It.i.Answer))'. Failure: Unable to formulate a join to express the SelectMany(c => Param{3}-IEnumerable`1).
     
    See InnerException for more details.
     
    Complete Expression:
     
    .Call System.Linq.Queryable.Select(
     
        .Call System.Linq.Queryable.ThenBy(
     
            .Call System.Linq.Queryable.OrderBy(
     
                .Call System.Linq.Queryable.Where(
     
                    .Call System.Linq.Queryable.SelectMany(
     
                        .Constant<Telerik.OpenAccess.Query.ExtentQueryImpl`1[Saadhana.DataLayer.FaqCategory]>(Extent<Saadhana.DataLayer.FaqCategory>()),
     
                        '(.Lambda #Lambda1<System.Func`2[Saadhana.DataLayer.FaqCategory,System.Collections.Generic.IEnumerable`1[Saadhana.DataLayer.FaqItem]]>),
     
                        '(.Lambda #Lambda2<System.Func`3[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem,VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem]]>))
     
                    ,
     
                    '(.Lambda #Lambda3<System.Func`2[VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem],System.Boolean]>))
     
                ,
     
                '(.Lambda #Lambda4<System.Func`2[VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem],System.Int32]>))
     
            ,
     
            '(.Lambda #Lambda5<System.Func`2[VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem],System.Int32]>))
     
        ,
     
        '(.Lambda #Lambda6<System.Func`2[VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem],VB$AnonymousType_1`3[System.String,System.String,System.String]]>))
     
     
     
    .Lambda #Lambda1<System.Func`2[Saadhana.DataLayer.FaqCategory,System.Collections.Generic.IEnumerable`1[Saadhana.DataLayer.FaqItem]]>(Saadhana.DataLayer.FaqCategory $c)
     
    {
     
        (System.Collections.Generic.IEnumerable`1[Saadhana.DataLayer.FaqItem]).Call (.Constant<Saadhana.BusinessLayer.DBHelperClasses.FaqHelper+_Closure$__1>(Saadhana.BusinessLayer.DBHelperClasses.FaqHelper+_Closure$__1).$VB$Local_context).GetAll()
     
    }
     
     
     
    .Lambda #Lambda2<System.Func`3[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem,VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem]]>(
     
        Saadhana.DataLayer.FaqCategory $c,
     
        Saadhana.DataLayer.FaqItem $i) {
     
        .New VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem](
     
            $c,
     
            $i)
     
    }
     
     
     
    .Lambda #Lambda3<System.Func`2[VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem],System.Boolean]>(VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem] $$VB$It)
     
    {
     
        ($$VB$It.c).Id == ($$VB$It.i).CategoryId
     
    }
     
     
     
    .Lambda #Lambda4<System.Func`2[VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem],System.Int32]>(VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem] $$VB$It)
     
    {
     
        ($$VB$It.c).OrderNo
     
    }
     
     
     
    .Lambda #Lambda5<System.Func`2[VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem],System.Int32]>(VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem] $$VB$It)
     
    {
     
        ($$VB$It.i).OrderNo
     
    }
     
     
     
    .Lambda #Lambda6<System.Func`2[VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem],VB$AnonymousType_1`3[System.String,System.String,System.String]]>(VB$AnonymousType_0`2[Saadhana.DataLayer.FaqCategory,Saadhana.DataLayer.FaqItem] $$VB$It)
     
    {
     
        .New VB$AnonymousType_1`3[System.String,System.String,System.String](
     
            ($$VB$It.c).CategoryName,
     
            ($$VB$It.i).Question,
     
            ($$VB$It.i).Answer)
     
    }


    This works fine

    Dim query = (From c In context.GetAll(Of FaqCategory)()
      Order By c.OrderNo
      Select c.CategoryName).ToList

    This works fine too

    Dim query = (From c In context.FaqCategories, i In context.FaqItems
                  Where c.Id = i.CategoryId
                  Order By c.OrderNo, i.OrderNo
                  Select c.CategoryName, i.Question, i.Answer).ToList


    This is my first project using Telerik Orm and I am using Database first.

    Thanks,
    B
  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 06 Feb 2014 Link to this post

    Hello Preet,

    that is strange. I tried to reproduce this here with C# and VB, but both versions work on my side:

    public void CrossJoinOrdered()
           {
               var q = from e in Scope.Extent<Northwind.Employee>()
                       from r in Scope.Extent<Northwind.Region>()
                       where e.Id == r.Id
                       orderby e.LastName, r.RegionDescription
                       select new { e.FirstName, r.RegionDescription };
               var x = q.ToList();
               Assert.AreEqual(4, x.Count);           
           }

    Public Sub CrossJoinOrdered_VB()
           Dim query = From e In Scope.Extent(Of Northwind.Employee)() _
                       From r In Scope.Extent(Of Northwind.Region)() _
                       Where e.Id = r.Id _
                       Order By e.LastName, r.RegionDescription _
                       Select e.FirstName, r.RegionDescription
           Dim x = query.ToList()
           Assert.AreEqual(4, x.Count)
       End Sub

    It could be related to the data model you are using. Also, which database system do you use?

    Regards,
    Thomas
    Telerik
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
  3. DevCraft banner
  4. Preet Kumar
    Preet Kumar avatar
    6 posts
    Member since:
    Mar 2007

    Posted 06 Feb 2014 in reply to Thomas Link to this post

    I am using MySQL.

    What is Scope.Extent? Is it same as context.GetAll ?

    Thanks,
  5. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 07 Feb 2014 Link to this post

    Hello Preet,

    yes, scope.Extent<X> is the same as context.GetAll<X>. Sorry for my mindless reply.

    Regards,
    Thomas
    Telerik
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
  6. Preet Kumar
    Preet Kumar avatar
    6 posts
    Member since:
    Mar 2007

    Posted 07 Feb 2014 in reply to Thomas Link to this post

    Hello Thomas,

    Can you suggest what should I try to avoid this error? I am using .Net 4.5, VS 2012. 

    I tried following and it works fine

    Dim query = (From i In context.GetAll(Of FaqItem)()
             Order By i.FaqCategory.OrderNo, i.OrderNo
             Select i.FaqCategory.CategoryName, i.Question, i.Answer).ToList

    Did you try running aforementioned code in Telerik Data Access using context.GetAll?

    Thanks,

  7. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 10 Feb 2014 Link to this post

    Hi Preet,

    I've tried with VB and both styles and I do not get a problem:

    <TestMethod()>
       Public Sub CrossJoinOrdered_VB_Context()
           Using ctx As VBContext = New VBContext(Me.CreateContext())
               Dim query = From e In ctx.Emloyees _
                           From r In ctx.Regions _
                           Where e.Id = r.Id _
                           Order By e.LastName, r.RegionDescription _
                           Select e.FirstName, r.RegionDescription
               Dim x = query.ToList()
               Assert.AreEqual(4, x.Count)
           End Using
       End Sub
     
       <TestMethod()>
       Public Sub CrossJoinOrdered_VB_Context_GetAll()
           Dim query = From e In Scope.Extent(Of Northwind.Employee)() _
                       From r In Scope.Extent(Of Northwind.Region)() _
                       Where e.Id = r.Id _
                       Order By e.LastName, r.RegionDescription _
                       Select e.FirstName, r.RegionDescription
           Dim x = query.ToList()
           Assert.AreEqual(4, x.Count)
       End Sub

    From the dump that you have sent before I conclude that the , and the _ could make a difference. Please check if wanted to use , or _ .

    Regards,
    Thomas
    Telerik
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
Back to Top
DevCraft banner