I have this model structure:
[Table("Image")]
public abstract class CBaseImage
{
public int ID { get; set; }
[Required]
public string Extension { get; set; }
[MaxLength(11)]
[Required]
public string OriginalUrl { get; set; }
[MaxLength(11)]
[Required]
public string ThumbUrl { get; set; }
public int OrderNumber { get; set; }
}
public class CNewBuildingLayoutImage : CBaseImage
{
public int NewBuildingLayoutID { get; set; }
public virtual CNewBuildingLayout NewBuildingLayout { get; set; }
[AImageFormat(527, 584, false)]
[MaxLength(11)]
[Required]
public string WH_527_584_Url { get; set; }
[AImageFormat(304, 342, false)]
[MaxLength(11)]
[Required]
public string WH_304_342_Url { get; set; }
}
and
[Table("NewBuildingLayout")]
public class CNewBuildingLayout
{
public int ID { get; set; }
//.........
public virtual ICollection<CNewBuildingLayoutImage> Images { get; set; }
}
At some point I need to use CNewBuildingLayout.Images
which is ICollection<CNewBuildingLayoutImage>
AS ICollection<CBaseImage>
,
but when I do:
(ICollection<CBaseImage>)someLayout.Images
I get:
Unable to cast object of type 'System.Collections.Generic.HashSet'1[Models.CNewBuildingLayoutImage]' to type 'System.Collections.Generic.HashSet'1[Models.CBaseImage]'.
I tried
(ICollection<CBaseImage>)someLayout.Images.Cast<CBaseImage>()
with same result.
How do I cast ICollection<Subclass>
to ICollection<BaseClass>
?