我在asp.net MVC2应用程序中工作,我有模型设计相关的问题。我有一个包含所有实体的edmx文件。我有一个视图模型命名whiteoutviewmodel它采用实体的三个单等三个集合是这样的:MVC2模型设计相关问题
public class WhiteoutViewModel
{
public List<Entities.Server> Servers { get; set; }
public List<Entities.Whiteout> Whiteouts { get; set; }
public List<Entities.Field> Fields { get; set; }
public ArrayList Hours {get;set;}
public ArrayList Minutes {get;set;}
public ArrayList AMPM {get;set;}
public ArrayList RepeatList{get;set;}
}
我创建基于此视图模型视图。现在我需要一个局部视图,它应该是 型号。我创建了一个whiteout类并在其中添加了一些属性。
public class WhiteoutDTO
{
public int WhiteoutId { get; set; }
public int FieldId { get; set; }
public int StartHour { get; set; }
public int StartMinute { get; set; }
public string StartTime { get; set; }
public int EndHour { get; set; }
public int EndMinute { get; set; }
public string EndTime { get; set; }
public string Repeats { get; set; }
public bool IsActive { get; set; }
public enmDays Days { get; set; }
}
现在我有两个Whiteout类。一个来自edmx,一个来自我创建的。我是否需要对edmx类型或我创建的类型进行局部视图?我创建我的类的原因是我需要一些不在数据库表/ edmx中的属性。我应该让我的whiteout类作为以上ViewModel的属性吗?
[编辑]
我有有whiteouts列表(EDMX)一个视图模型,我还需要一个白化,所以我的视图模型可以有这样的:
public class viewmodel {
// of edmx entity type
public List<Entities.Whiteout> Whiteouts { get; set; }
// of my DTO type where my DTO has some properties which are not in edmx whiteout entity
public WhiteoutDTO myWhiteout {get;set;}
}
我也想我的主要观点类型为Whiteouts的地方,这是我的myWhiteout类型的部分视图。这是可能的,而且是很好的做法。我可以将mywhitout从主视图传递到主视图为Whiteouts类型的局部视图。
现在我已经包含了这样的局部视图:
Html.RenderPartial("WhiteoutList", Model);
请建议
我已经更新了这个问题。请查看ViewModel的详细信息 – DotnetSparrow 2011-06-03 05:45:13