hi,
I have an existing class Image which is used extensively throughout my application. I need to return a generic list of images (List) to the frontend but as there is no stored proc in the 3ed party DB I am quering I need to use Linq to Sql.
I have create a dbtm file of the database I am quering in my DAL which looks like:
ImageCat
    ImageId
    Name
    Width
    DateModified
    Height
    CatId
My Image class is as follows
public class Image
{
 public int Id { get; set; }
 public string Name { get; set; }
 public int Width { get; set; }
 public int Height { get; set; }
}
My Linq to Sql is as follows:
var imageList = (from ic in db.ImageCats
   where ic.CatID.Contains(category)
 select ic).ToList();
var finalImageList = new List<Image>();
foreach (ImageCat ic in imageList)
{
 Image image = new Image();
 image.Id= ic.ImageID;
 image.Height = (int)ic.Height;
 image.Name = ic.Name;
 image.Width = (int)ic.Width;
 finalImageList.Add(image);   
}
I dont want to be looping through the linq to Sql result to setup my List. Is there an easier way. What is best practice? I dont like the idea of exposing my dbml classes to the presentation layer.