我最近在我的另一个问题上发布了以下代码。请原谅部分属性,这是我Wanted
要做的,但不能......
public partial class Agency : PropertyValidator, IAgency
{
private string _name;
public partial string Name
{
get { return _name; }
set
{
// PropertyValidator stuff
if (string.IsNullOrEmpty(value))
AddErrorToProperty("Agency name must contain a reasonable alphanumeric value.");
if (string.IsNullOrWhiteSpace(value))
AddErrorToProperty("Agency name cannot contain all spaces.");
SetPropertyIfValid(ref _name, value);
}
}
}
和
public partial class Agency : IPersitentEntity, IAgency
{
[Key] // NOTE these Annotations are because of Entity Framework...nice separation!
public int ID { get; set; } // From IPersitentEntity
[Required]
[MinLength(3), MaxLength(50)]
public partial string Name { get; set; } // IAgency NOTE this is not valid, but the
// separation is amazing!
// From IPersitentEntity provide CRUD support
public void Create() { throw new NotImplementedException(); }
public void Retrieve(int id) { throw new NotImplementedException(); }
public void Update(int id) { throw new NotImplementedException(); }
public void Delete(int id) { throw new NotImplementedException(); }
}
...在其中,我有一条评论没有回复 stackoverflow 说...
You might want to read up on persistence ignorance and why making each of your entities inherit from IPersitentEntity is a "bad thing".
以前没听说过Persistence Ignorance
,不得不查。原来我知道这个概念是什么,而不是术语。但是,我有点困惑为什么我在做的事情很糟糕。