views:

203

answers:

1

I am learning linq to sql and I am trying to setup a lookup combo box in my web page. I was using a linq data source but I then moved my linqtosql code to it's own class library for my DAL dll (took out of app_code folder). So, I am converting the page code to be able to still have lookups driven now by a biz object.

Here's what I have done in my biz layer...

Public Class KosherTypes

    Public Shared Function GetKosherTypes() As List(Of KosherTypeLookup)
        Dim db As New DBDataContext

        Dim types = From kt In db.KosherTypes _
                    Where kt.IsDeleted = False _
                    Order By kt.Name _
                    Select New KosherTypeLookup With {.Name = kt.Name, .ID = kt.KosherTypeID}

        Return types.ToList

    End Function

End Class

I then setup an object data source and mapped it to this class.

I have a few questions as when I was doing internet searches I didn't find anyone that seemed to be doing this and yet I know lookup tables / combo boxes are common...

  1. Did I totally just miss something and there are better way(s) to do this?

  2. I went with returning a list but I could have returned an IEnumerable or IQueryable. In my reading it seemed IQueryable had more functionality for linq to sql but since I am returning a simple two column list then I only need to return an IEnumerable or List. I went with a List since it's strongly typed. Did I make a good decision? AKA - Should I just have returned and IEnumerable or perhaps gone with IQueryable?

Thanks!

+1  A: 

I'll answer in reverse order:

  1. I wouldn't use IQueryable outside of your repos / DAL for the simple reason that since execution is deferred, you lose control of what exactly is executed (i.e., an aribtrary function could be assigned as a delegate for WHERE), making maintenance and testing much harder. I don't see an issue with you returning an IEnumberable(Of KosherTypeLookup) though.
  2. If the lookup is a static lookup that never or rarely changes, you might want to look at a way to cache the lookup after the first use, to avoid having to hit the db every time that box is called. It really depends on your expected load, though. As always, performance/load testing will highlight where you need to optimize.
Josh E