BLL With LINQ
Hello,
I am currently working on a little project I call GeekTube, it is going to be an internal repository for videos. Implementing my BLL has never been easier. My approach has been to implement all my static helpers as part of a partial class. For example:
partial class Video {
public static Video GetVideo(GeekTubeDataContext db, long ID) {
Video vid = db.Videos.FirstOrDefault(p => p.ID == ID);
return vid;
}
public static IEnumerable<Video> GetVideos(GeekTubeDataContext db) {
var videos = (from video in db.Videos
select video);
return videos;
}
public static IEnumerable<Video> GetVideosInCategory(GeekTubeDataContext db, long CategoryID) {
var videos = (from video in db.Videos
where video.CategoryID == CategoryID
select video);
return videos;
}
*** SNIP ***
}
Then from the frontend simply use something like:
GeekTubeDataContext db = new GeekTubeDataContext();
var videos = Video.GetVideos(db);
With the GetVideosInCategory method. This maybe should be done by loading a category and getting its videos via the realationship, i.e.:
var videos = Category.GetCategory(db, 1).Videos;
But this runs two SQL queries one to load the category and the other that loads the videos. This is find in a case when I will use both but sometimes I may only want to get the videos so the need for the extra method.
Anyone with an oppinion on better ways to do this with LINQ would be good. Look forward to posting more useful information as I progress more with the project.
Cheers
Stefan