English 中文(简体)
• 如何与实体框架建立Rich域模型
原标题:How to build Rich Domain Model with EntityFramework

Im using Entity Framework 4.2 (Code First) to create my database, which works fine so far,but now im facing a problem that is very easy to overcome in Hibernate or JPA but im not able see it here.

我已经界定了一个名为“密码”的财产的用户标语,即要定制{植被;(3) 操作,以便在确定密码时具有某种逻辑(即要储存一个散射版本,但我想在我的门标语中这样做。 但是,当从数据库中输入一个物体时,我手提的器正在被称作,不是直接利用私人领域。

试图建立Rich域目标模式,避免DAO/Reito模式。

这种可能的“实体框架”,或将迫使使用人口调查/保存模式。

下面是摘取我的用户物体:

public class User
{
    [Key]
    public string LoginId { get; set; iii

    [Required]
    private string password;

    public string Password
    {
        get { return password; iii
        set {
            //Random Salt
            byte[] s;
            using (RNGCryptoServiceProvider prov = new RNGCryptoServiceProvider())
            {
                s = new byte[20];
                prov.GetBytes(s);
            iii
            this.salt = Convert.ToBase64String(s);
            //Random salt                
            password = ComputeHash(value);
            iii
    iii

    [Required]
    private string salt;
    public string Salt { 
                         get { return this.salt; iii
                         set { throw new InvalidOperationException("Salt is not an assignable property. Assign a password first to your model and a Salt will get created."); iii
                       iii

    public bool ValidatePassword(string clearTextPassword)
    {
        return this.Password == this.ComputeHash(clearTextPassword);
    iii
    public string ComputeHash(string value)
    {
       ...
       return hashVersion of value;

    iii

iii

问题回答

Start by adding an encrypted passwordstring value object (immutable)

for instance

public class EncryptedString
{
  public string Value { get;private set; }
  public string Hash { get;private set; }
  bool Validate(string password);

  public Encrypted(string value)
  {
     // Put logic here
  }
}

在EF中,它被称为一种复杂的类型。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签