开发者

Writing computed properties with NHibernate

I'm using NHibernate 2.1.2 + Fluent NHibernate

I have a ContactInfo class and table. The Name column is encrypted in the database (SQL Server) using EncryptByPassphrase/DecryptByPassphrase.

The following are the relevant schema/class/mapping bits:

table ContactInfo(
  int Id,
  varbinary(108) Name)

public class ContactInfo
{
  public virtual int Id { get; set; }
  public virtual string Name { get; set; }
}

public class ContactInfoMap : ClassMap<ContactInfo>
{
  public ContactInfoMap()
  {
    Id(x => x.Id);
    Map(x => x.Name)
      .Formula("Convert(nvarchar, DecryptByPassPhrase('passphrase', Name))");
  }
}

Using the Formula approach as above, the values get read correctly from the database, but NHibernate doesn't try to insert/update the values when saving to the database (which makes sense).

The problem is that I would like to be able to write the Name value using the corresponding EncryptByPassPhrase function. I'm unsure if NHibernate supports this, and if it does, I haven't b开发者_运维技巧een able to find the correct words to search the documentation effectively for it.

So... how can I write this computed property back to the database with NHibernate?

Thanks in advance!


A property mapped to a formula is read-only.

A named query wrapped up in a ContactInfoNameUpdater service might be one way to solve the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜