Fluent API example in VB

Posted by Community Admin on 03-Aug-2018 14:43

Fluent API example in VB

All Replies

Posted by Community Admin on 09-Aug-2010 00:00

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

Posted by Community Admin on 09-Aug-2010 00:00

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

Posted by Community Admin on 09-Aug-2010 00:00

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;
                  );
    

Posted by Community Admin on 10-Aug-2010 00:00

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

Posted by Community Admin on 23-Feb-2011 00:00

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??




Posted by Community Admin on 01-Mar-2011 00:00

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

Posted by Community Admin on 26-Oct-2011 00:00

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.

Posted by Community Admin on 27-Oct-2011 00:00

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

This thread is closed