Linq Help please

Posts   
 
    
DelG
User
Posts: 18
Joined: 11-Jan-2007
# Posted on: 25-Sep-2008 12:00:30   

Hi All, I am trying to make this query in my code,

SELECT MAX(dateruleto) FROM dbo.PackageRulesDateBreak WHERE dateruleto <= '16-SEP-2008'

However I cant quite see how to make it work. This is part of a function i have The code is in-complete becuase I am stuck simple_smile



    Private Function SplitDates(ByVal iPackageID As Integer, _
                                ByVal iPackageNights As Integer, _
                                ByVal dtFromDate As Date, _
                                ByVal dtToDate As Date) As Date

        Dim PackageDates As New PackageRulesDateBreakCollection()
        Dim metaData As New LinqMetaData()
        Dim max = metaData.PackageRulesDateBreak _

What I want to do is return the max 'PackageRulesDateBreak .DateTo' which is <= to the var dtFromDate which is passed in ByVal in the Function Signature.

I have looked at the documentation but I cant work it out. There is a line in the docs that says "Dim max = metaData.Order.Max(Function(o) o.OrderDate)" but I dont get that at all. sorry if I am missing something real easy here.

Any help would be great. Thanks Jason

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 25-Sep-2008 13:25:33   

In C# I can write it as:

var q = (from c in metaData.Categories
                    where c.CategoryId < 5
                        select c.CategoryId).Max();

Can you convert this to VB, coz I'm not that expert with VB flushed ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39863
Joined: 17-Aug-2003
# Posted on: 26-Sep-2008 10:31:07   
Dim q = (From c In metaData.Categories _
                    Where c.CategoryId < 5 _
                     Select c.CategoryId).Max()

There sunglasses

Frans Bouma | Lead developer LLBLGen Pro
DelG
User
Posts: 18
Joined: 11-Jan-2007
# Posted on: 01-Oct-2008 16:48:58   

Otis wrote:

Dim q = (From c In metaData.Categories _
                    Where c.CategoryId < 5 _
                     Select c.CategoryId).Max()

There sunglasses

Thanks Guys..

Jason