我的问题在于继承。
我有一个Actor类
使用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 { 公共类公司:演员 { private string _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; }
}
}
当我打电话
演员演员= _actorRepository.Get(id);
它工作正常。我得到了正确的演员类型 - &gt;公司或联系
问题是我将Actor类与另一个类嵌入如下。
使用System; 使用System.Collections.Generic; 使用NHibernate.Validator.Constraints; 使用SharpArch.Core; 使用SharpArch.Core.DomainModel;
命名空间ProTeria.NET.Common.Domain { 公共类文章:实体 { private string _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 = _articleRepository.Get(articleId);
article.Sender将无法正确映射,它是基本类型,而不是派生类型。
我不确定我做错了什么。