score:0

That seems OK, but you've tagged your question as ASP.Net. My question to you is how large is this list and how often are you displaying this page?

If you are displaying it often and it isn't too large, I'd pull the slider table into memory and then run your query without hitting the DB.

In fact if possible you would cache the entire slider and slideritems if you can.

Even if you cache the most recently used if it makes sense to your app, not having to hit the DB will give you a better perf increase than optimising what appears to be a very trivial parent / child relationship. I assume you have an index in the database down tbl.Id?

score:0

I suggest you can use Linq query with join and put the data into the list. It works well for you.

score:1

If your database already has the foreign key relationship between Sliders and SliderItems in place AND if your LINQ-to-SQL model includes both Sliders and SliderItems, then searching for a Slider automatically retrieves all related SliderItems:

public static IEnumerable<SliderItems> GetSliderItems(Guid sliderId)
{
    using (DataContext dc = new DataContext())
    {
        Slider result = dc.Sliders.Single(s => s.Id == sliderId);

        return result.SliderItems;
    }
}

Related Articles