Проблема наследования Sharp Architecture - PullRequest
1 голос
/ 01 июля 2011

моя проблема с наследованием.

У меня есть актерский класс

с использованием System.Collections.Generic; используя SharpArch.Core; использование SharpArch.Core.DomainModel;

Пространство имен ProTeria.NET.Common.Domain { публичный класс Актер: сущность { публичный актер () { В этом(); }

    private void Init()
    {
        Addresses = new List<Address>();
    }

    public virtual Account Account { get; set; }
    public virtual string Number { get; set; }
    public virtual string Telephone { get; set; }
    public virtual string Fax { get; set; }
    public virtual string Email { get; set; }
    public virtual string IdNumber { get; set; }
    public virtual CountryCode Country { get; set; } 

    public virtual IList<Address> Addresses { get; set; }

    public virtual void AddAddress(Address address)
    {
        address.Actor = this;
        Addresses.Add(address);
    }
}

}

, а также два производных класса,

с использованием System.Collections.Generic; используя SharpArch.Core; использование SharpArch.Core.DomainModel;

Пространство имен ProTeria.NET.Common.Domain { Общественный класс Компания: Актер { приватная строка _companyName;

    protected Company()
    {
         Init();
    }

    public Company(string companyName)
        : this()
    {
        Check.Require(!string.IsNullOrEmpty(companyName) && companyName.Trim() != string.Empty,
                      "Company name must be provided");
        _companyName = companyName;
    }

    private void Init()
    {
        Employees = new List<Employee>();
    }

    public virtual Account Account { get; set; }
    public virtual string EoriNumber { get; set; }

    [DomainSignature]
    public virtual string CompanyName
    {
        get { return _companyName; }
        protected set { _companyName = value; }
    }

    public virtual CompanyNcts CompanyNcts {get;set;} 
    public virtual IList<Employee> Employees { get; set; }

    public virtual void AddEmployee(Employee employee)
    {
        employee.Company = this;
        Employees.Add(employee);
    }
}

} и

с использованием SharpArch.Core; использование SharpArch.Core.DomainModel;

пространство имен ProTeria.NET.Common.Domain { общедоступный класс { приватная строка _foreName;

    protected Contact()
    {
    }

    public Contact(string foreName)
        : this()
    {
        Check.Require(!string.IsNullOrEmpty(foreName) && foreName.Trim() != string.Empty,
                      "Contact first name must be provided");
        _foreName = foreName;
    }

    public virtual Account Account { get; set; }


    [DomainSignature]
    public virtual string ForeName
    {
        get { return _foreName; }
        protected set { _foreName = value; }
    }

    public virtual string Surname { get; set; }
    public virtual string Mobile { get; set; }

}

}

Когда я звоню

Actor actor = _actorRepository.Get (id);

работает нормально. И я получаю правильный тип актера -> компания или контакт

Проблема в том, что я встраиваю класс Actor в другой класс, как показано ниже.

с использованием системы; using System.Collections.Generic; использование NHibernate.Validator.Constraints; используя SharpArch.Core; использование SharpArch.Core.DomainModel;

namespace ProTeria.NET.Common.Domain { публичный класс Статья: сущность { приватная строка _number;

    public Article(string number, Account account)
        : this()
    {
        Check.Require(!string.IsNullOrEmpty(number)
                      && number.Trim() != String.Empty,
                      "ArticleNumber must be provided");

        Check.Require((account != null), "Account must be provided");

        _account = account;

        _number = number;
    }

    protected Article()
    {
         Init();
    }


    private void Init()
    {
        Descriptions = new List<ArticleDescription>();
        UnitPrices = new List<ArticlePrice>();
    }

    private Account _account;
    public virtual Account Account
    {
        get { return _account; }
        set { _account = value; }
    }

    [DomainSignature]
    [NotNull, NotEmpty]
    public virtual string Number
    {
        get { return _number; }
        protected set { _number = value; }
    }

    public virtual Actor Sender { get; set; }
    public virtual CurrencyCode CurrencyCode { get; set; }
    [NotNull]
    public virtual LanguageCode LanguageCode { get; set; }
    public virtual ArticleNcts ArticleNcts { get; set; }
    public virtual ArticleDe ArticleDe { get; set; }
    public virtual ArticleSe ArticleSe { get; set; }
    public virtual ArticleNo ArticleNo { get; set; }
    public virtual CountryCode CountryCode { get; set; }
    public virtual HsCode HsCode { get; set; }
    public virtual double GrossWeight { get; set; }
    public virtual double NetWeight { get; set; }
    public virtual string ExportCode { get; set; }
    public virtual string ImportCode { get; set; }
    public virtual string TaricCode { get; set; }
    public virtual IList<ArticleDescription> Descriptions { get; set; }
    public virtual IList<ArticlePrice> UnitPrices { get; set; }

    public virtual void AddArticleDescription(ArticleDescription articleDescription)
    {
        Descriptions.Add(articleDescription);
    }

    public virtual void AddArticlePrice(ArticlePrice articlePrice)
    {
        UnitPrices.Add(articlePrice);
    }
}

}

Тогда, если я позвоню

Article article = _articleRepository.Get (articleId);

article.Sender не будет отображаться правильно, он в базовом типе, а не в производном.

Я не уверен, что делаю что-то не так.

...