I have parent class
public class ImageInfo {}
and child
public class ImageInfoVM: ImageInfo {
//fields
public ImageInfoVM(ImageInfo img)
{
this.name = img.name; //etc
}
I'm trying to read data from database with IEnumerable<ImageInfo> model = db.ImageInfo.ToList()
and assign this data to ImageInfoVM iivm
, but no success at this.
I have tried this solution https://stackoverflow.com/a/9885823/632224, which i think is what i need to do, but i'm getting error The class 'ImageInfoVM' has no parameterless constructor
. in this query
List<ImageInfoVM> iivm = model.Select(m => new ImageInfoVM(m)).ToList();
Can someone help with this?