1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Fluent API example in VB

Fluent API example in VB

8 posts, 0 answered
  1. Peter
    Peter avatar
    3 posts
    Registered:
    18 May 2009
    09 Aug 2010
    Link to this post
    Hi,

    Can someone provide me with a simple sample of the fluent API code but in VB.Net? I've tried a conversion tool on one of Ivan's examples, but it doesn't produce valid code!

    Thanks,

    Pete
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Aug 2010
    Link to this post
    Hi Peter,

    It would be easier if you provide us the Fluent API code that you use. There are many samples and scenarios and it is not clear which one you are refering to.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Peter
    Peter avatar
    3 posts
    Registered:
    18 May 2009
    09 Aug 2010
    Link to this post
    Hi Ivan

    Example from the help file:

    using (var fluent = App.WorkWith())
    {
        // create 10 content items
        for (int i = 0; i < 10; i++)
        {
            fluent.ContentItem()
                  .CreateNew()
                  .Do(ci =>
                      {
                          ci.Title = "Content item " + i.ToString();
                          ci.Author = "Ivan";
                      });
        }
     
        // create 20 events
        for (int i = 0; i < 20; i++)
        {
            fluent.Event()
                  .CreateNew()
                  .Do(ev =>
                      {
                          ev.Title = "Event " + i.ToString();
                          ev.EventStart = DateTime.Now;
                      });
        }
    }

  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    10 Aug 2010
    Link to this post
    Hello Peter,

    We used the converter from converter.telerik.com, and here is the resulted code:

    Using fluent = App.WorkWith()
        ' create 10 content items
        For i As Integer = 0 To 9
            fluent.ContentItem().CreateNew().[Do](Function(ci) Do
                ci.Title = "Content item " + i.ToString()
                ci.Author = "Ivan"
            End Function)
        Next
     
        ' create 20 events
        For i As Integer = 0 To 19
            fluent.[Event]().CreateNew().[Do](Function(ev) Do
                ev.Title = "Event " + i.ToString()
                ev.EventStart = DateTime.Now
            End Function)
        Next
    End Using
     
    '=======================================================
    'Service provided by Telerik (www.telerik.com)
    'Conversion powered by NRefactory.
    'Twitter: @telerik, @toddanglin
    'Facebook: facebook.com/telerik
    '=======================================================

    All the best,
    Georgi
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Shawn Krivjansky
    Shawn Krivjansky avatar
    18 posts
    Registered:
    11 Jan 2010
    23 Feb 2011
    Link to this post
    I'm using VB.
    I am trying to locate an ALBUM by Album name with the Fluent API.

    It seems NO MATTER what I try, the following will blow up with an "Index out of range" problem... It is something with the WHERE.
    App.WorkWith.Albums.Where(Function(a) a.Title.Value.ToString = "AlbumName").Get.First

    I can get a list of albums ok...
    I can get the FIRST album ok (by just pulling pulling the first off the stack)...
    But, when I try to filter with the WHERE, it will ALWAYS blow up.

    Now... If I do the following:
    App.WorkWith.Albums.Get.ToList.Where(Function(a) a.Title.Value.ToString = "AlbumName").Get.FirstOrDefault
    This DOES work.
    Notice how I did the WHERE after I cut my ties to the Fluent API LINQ implementation (i.e. after the ToList).

    So, does that tell me that there is a serious bug in the VB Fluent API LINQ implementation???
    I see this very simile code in C# examples all over the place and nobody is complaining, but I can't do a very simple WHERE with the VB implementation.

    What is going on here??




  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    01 Mar 2011
    Link to this post
    Hi Shawn Krivjansky,

    As we have already discussed this issue in a support ticket I am going to quickly summarize the problem.

    This is a problem of the Sitefinity OQL parser and should be resolved with the 2011 Q1 release, when we change the OQL parser to the Telerik OpenAccess built in one. There is a PITS item which you can track for status updates on this issue.

    Kind regards,
    Radoslav Georgiev
    the Telerik team
  7. Shawn Krivjansky
    Shawn Krivjansky avatar
    18 posts
    Registered:
    11 Jan 2010
    26 Oct 2011
    Link to this post
    Just wanted to give an update after 8 months...
    I ran into this same problem again...  Still not fixed.  Still "IN PROGRESS" in the PITS system.

    I'm not holding my breath.

    Guess I'll just continue to hit this same problem everytime I try to do something.
  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    27 Oct 2011
    Link to this post
    Hi Shawn Krivjansky,

    We have replaced the Sitefinity OQL parser in 4.1 and these types of queries do work. Please consider bellow example:
    Dim album = App.WorkWith().Albums().Where(Function(a) a.Title.Equals("Opportunities")).Get.FirstOrDefault


    Now if you are trying to filter by properties that are not mapped to database fields, then yes you will not be able to do where clause on Linq to SQL, because the field does not exist in database. An example for this is the Album property of image, which is a copy of the mapped field Parent. In this case you have to use:
    Dim album = App.WorkWith().Albums().Where(Function(a) a.Title.Equals("Opportunities")).Get.FirstOrDefault
    Dim images = App.WorkWith.Images.Publihed.Where(Function(img) img.Parent.Id = album.Id).Get


    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
8 posts, 0 answered