Does NHibernate always require a parameterless constructor?

by w0051977   Last Updated December 07, 2017 18:05 PM

Please see the code below:

public class Email
    private readonly string _value;
    private Email(string value)
        _value = value;

    public static Result<Email> Create(string email)
        if (string.IsNullOrWhiteSpace(email))
            return Result.Fail<Email>(“E-mail can’t be empty”);
        if (email.Length > 100)
            return Result.Fail<Email>(“E-mail is too long”);
        if (!Regex.IsMatch(email, @”^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$”))
            return Result.Fail<Email>(“E-mail is invalid”);
        return Result.Ok(new Email(email));
    public static implicit operator string(Email email)
        return email._value;
    public override bool Equals(object obj)
        Email email = obj as Email;
        if (ReferenceEquals(email, null))
            return false;
        return _value == email._value;
    public override int GetHashCode()
        return _value.GetHashCode();

which I took from here:

In the comments the author says: "That's because of ORMs. Generally speaking, ORMs don't handle mapping on structs very well, that's why I use classes" indicating that he has considered ORMs. In other posts he talks about using NHibernate. However, NHibernate requires a parameterless constructor. Doesn't it? Can this code be mapped to a database field as it is?

Related Questions

Should the domain layer be dependant on NHibernate?

Updated October 18, 2017 13:05 PM