用=“” entity =“” framework =“”

时间:2019-01-20 19:04:46

标签: c# arrays list entity-framework

=“”

我要保存字节数组列表(List

该类如下:

public class ShootingLocation : LocationBase
{
    #region attributes
    public ParkingLocation ParkingLocation { get; set; }

    [MaxLength(16), Column(TypeName = "Binary")]
    public List<byte[]> LocationPhotos { get; set; }
    #endregion

    #region constructors
    public ShootingLocation()
    { 
    }
    #endregion
}

当我尝试保存DbContext时,它会引发异常。任何热门或替代解决方案?

1 个答案:

答案 0 :(得分:0)

如果要在每个拍摄位置存储几张照片,则数据库中需要建立1到n的关系,即,必须具有第二个与照片相关的类/表

public class ShootingLocation : LocationBase
{
    public int ShootingLocationID { get; set; }

    public ParkingLocation ParkingLocation { get; set; }

    // Navigation property
    public ICollection<Photo> Photos { get; set; }
}

public class Photo
{
    public int PhotoID { get; set; }
    public string Description { get; set; }
    public byte[] ImageBytes { get; set; }

    // Navigation properties
    public int ShootingLocationID { get; set; }
    public ShootingLocation ShootingLocation { get; set; }
}