English 中文(简体)
2. 液化NHibernate: 1. 对通过构成部分绘制的财产图的所有成员适用属性
原标题:Fluent NHibernate: Applying attribute to all members of a property mapped via a Component

我正在使用Fluent NHibernate(1.2),并正在着手实施一栏加密。 我有处理加密的习惯类型,因此,域模型可以有本土的清晰文本数据类型(简单明细、插图、日期等),所有加密/加密工作都落后于现场。

我愿具体指出,每个领域模式中哪些财产通过属性进行加密,并利用《公约》规定这些特性的习惯类型,因此,域模型为ice,而无需提及习俗类型:

public class EncryptedAttribute : Attribute {}

public class UserRecord {
  public virtual Guid Id { get; set; }
  public virtual string Username { get; set; }
  [Encrypted]
  public virtual string EmailAddress { get; set; }
  [Encrypted]
  public virtual DateTime DateOfBirth { get; set; }
  [Encrypted]
  public virtual PersonName LegalName { get; set; }
  // etc.
}

public class PersonName {
  public virtual string Given { get; set; }
  public virtual string Middle { get; set; }
  public virtual string Family { get; set; }
}

public class EncryptedColumnConvention
  : AttributePropertyConvention<EncryptedAttribute> {
  protected override void Apply(
    EncryptedAttribute attribute, IPropertyInstance instance)
  {
    var dbType = typeof(EncryptedColumnType<>).MakeGenericType(domainType);
    instance.CustomType(dbType);  
  }
}

public class UserRecordMap : ClassMap<UserRecord> {
  public UserRecordMap() {
    Id(o => o.Id);
    Map(o => o.Username);
    Map(o => o.EmailAddress);
    Map(o => o.DateOfBirth);
    Component(o => o.LegalName).ColumnPrefix("LegalName");
    // etc.
  }
}

public class PersonNameMap : ComponentMap<PersonName> // etc.

如上文所述,我正试图将这一切与《阿特图堡公约》联系起来。 这对简单的特性来说是好的,例如: 电子邮件地址将采用加密式ColumnType的习俗类型。

But it is not working for properties which are complex types (e.g. LegalName) that are mapped via Components. What I want is to encrypt every property of LegalName because I decorated it with [Encrypted]. In other words, I want the UserRecord db table to have three encrypted name fields--given, middle, and family.

看来《公约》根本不适用于法律协会或其任何成员的财产。 或许 我需要使用另一种类型的公约来处理这种情况?

我知道,我只能将个人财产与[加密]脱钩,而不是在用户记录中纠正[法律名称]财产。 我对此进行了测试,并做了罚款。 必要时,我可以回头处理这种做法,但有兴趣设法使上述办法大纲发挥作用。

最佳回答

其后,我没有找到直接执行我所述情况的办法。 我可以认为,根据C#中的特性如何工作,很难或不可能执行这样的事情。

相反,我只添加了<代码>[加密],对<代码>PersonName类别的每一财产作了说明,并允许随后的数据库表中的<代码>PersonName栏始终被加密。 今后,如果我确实需要将<代码>PersonName作为另一个实体的非加密“兼容”加以测绘,我或许可以将非加密的类别与以下特性脱钩: 对其所有地图栏/组件的加密,优先于任何<编码>>[加密] 在该类财产/组合图中发现的属性。

问题回答

暂无回答




相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签