product.cs

来自「NHibernate简单DEMO」· CS 代码 · 共 47 行

CS
47
字号
using BasicSample.Core.Utils;

namespace BasicSample.Core.Domain
{
    public class Product : DomainObject<long>
    {
        /// <summary>
        /// Needed by ORM for reflective creation.
        /// </summary>
        private Product() { }

        public Product(string productName, Supplier suppliedBy) {
            ProductName = productName;
            SuppliedBy = suppliedBy;
        }

        public string ProductName {
            get { return productName; }
            set {
                Check.Require(!string.IsNullOrEmpty(value), "ProductName may not be null or empty");
                productName = value;
            }
        }

        public Supplier SuppliedBy {
            get { return suppliedBy; }
            // Assume that it doesn't make sense to ever change the supplier of a product
            protected set {
                Check.Require(value != null, "SuppliedBy may not be null");
                suppliedBy = value;
            }
        }

        /// <summary>
        /// Hash code should ONLY contain the "business value signature" of the object and not the ID
        /// </summary>
        public override int GetHashCode() {
            return (GetType().FullName + "|" +
                    ProductName + "|" +
                    SuppliedBy.GetHashCode()).GetHashCode();
        }

        private string productName;
        private Supplier suppliedBy;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?