2012-07-29 69 views
0

有两个对象,人物和图像。 Person应该已经存储了id int的内部数据库,以便使用src属性正确地呈现图像。是这个值对象

考虑以下情形

  1. 图像是使用web表单(MVC)
  2. Person实体使用网络形式(MVC)和JavaScript创建用于检索选定的(多个)图像ID来存储内部上传人物形象财产
  3. 在这些人图像属性加载IMG SRC attrubute内显示图像

的看法方面,你会如何德兴Person对象

Person.cs 
Id int not null 
// To do 

Image.cs

Id int not null 
ImagePath string not null 
AlternateText string 
+0

没有足够的信息来确定。在做出答案之前,还需要了解有关域的更多信息。应用程序中的人员是否具有唯一性?做图像?没有人,图像是否有意义?没有图像的人是否有意义? – Oded 2012-07-29 18:12:38

+0

为什么不在图像上使用外键来绑定Person id。它允许你在一方只有id属性的Person类和一个id为Person ID(外键)的图像类 – 2012-07-29 18:20:20

+0

一般来说,如果你的对象有一个'Id'属性,它不是一个值对象。它是一个实体。 – danludwig 2012-07-30 00:30:42

回答

2
class PersonViewModel 
{ 
    int Id {get; set;} 
    int ImageId {get; set; 
} 

请注意,这是一个视图模型,为你的MVC表示层特别定制。

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(); 
     }} 

} 
相关问题