私のASP.NET MVC 3プロジェクトでは、別のクラスライブラリプロジェクト内にリポジトリパターンを実装しました。IValidatableObjectとDependency Injectionのサポート
また、ORMとしてEFを使用しています。また、私はIValidatableObejct
インターフェイスでいくつかのモデル検証を実装しました。私が代わりに直接IAccommPropertySeasonPeriodAliasRepository
を使用してのAccommPropertySeasonPeriodAliasRepository
クラスを使用しているので、あなたが今から、ご覧のように私のモデルは完全に密結合、
[MetadataType(typeof(AccommPropertySeasonPeriodAlias.MetaData))]
public partial class AccommPropertySeasonPeriodAlias : IValidatableObject {
private class MetaData {
[StringLength(5), Required]
[Display(Name = "Period Alias Name")]
public string AccommPropertySeasonPeriodAlias1 { get; set; }
}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
var repo = new AccommPropertySeasonPeriodAliasRepository();
if (repo.GetAll(this.AccommPropertySeasonID).
Where(x => x.AccommPropertySeasonPeriodAlias1 == this.AccommPropertySeasonPeriodAlias1) != null)
yield return new ValidationResult("Alias Name needs to be unique");
}
}
:ここではそれがどのように見えるかです。ユニットテストのための
私のモデルができるように、この権利を行う方法で、よく、(これは右の単語であるかどうかわからない)何偽-でき?
全く私が探していたもの。どうもありがとう! – tugberk