【发布时间】:2011-09-01 09:32:54
【问题描述】:
假设我有这样的课程
public class Blog{
[Key]
public int ID{get;set;}
//these can only be tags that are in the tags db table
IEnumerable<string> Tags{get;set;}
//validation pseudocode to illustrate issue
public bool IsValid() {
//this is my issue-- how do i get my db context/repository
//into my validation logic for this class? i need it
var goodTags=db.Tags.Select(i=>i.Name);
//if this tag isn't a "goodTag", then this shouldnt validate
Tags.ForEach(i=> {
if(!goodTags.Contains(i))
return false;
});
}
}
如何在不将数据访问逻辑放入模型中的情况下验证标签中包含的字符串是否在标签数据库表中?我正在使用 MVC3。你是怎么做到的?
谢谢!
【问题讨论】:
标签: asp.net validation asp.net-mvc-3 architecture