有两个对象,人物和图像。 Person应该在db中存储id int,以使用src属性正确呈现图像。
考虑以下方案
你如何设计Person对象
Person.cs
Id int not null
// To do
Image.cs
Id int not null
ImagePath string not null
AlternateText string
答案 0 :(得分:2)
class PersonViewModel
{
int Id {get; set;}
int ImageId {get; set;
}
请注意,这是一个视图模型,尤其适合您的mvc表示层。
答案 1 :(得分:0)
假设您正在使用EF或类似的东西,您可以像这样设计类。
public class Image
{
public int Id { get; set; }
public string ImagePath { get; set; }
public string AlternateText { get; set; }
public int PersonId { get; set; }
}
public class Person
{
public int Id { get; set; }
public List<Image> Images {
get
{
return DbContext.Images.Where(image => image.PersonId == this.Id).ToList();
}}
}