当我尝试制作FK参考时遇到问题。我得到一个MappingException
NHibernate.MappingException:无法确定类型:Jps.Internal.Domain.Model.User,> JpsCore,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null,对于列:NHibernate.Mapping.Column(DeptorSsoId)
我的实体看起来像这样
public class PayExAgreement : EntityBase
{
public int SubscriptionNumber { get; set; }
public User DeptorSso { get; set; }
public string PayExAgreementRef { get; set; }
public string PayExMaskedNumber { get; set; }
public string PayExPaymentMethod { get; set; }
public DateTime PayExPaymentMethodExpireDate { get; set; }
public IList<SubscriptionOrder> SubscriptionOrderList { get; set; }
}
public class User : EntityBase
{
public Guid SsoId { get; set; }
public string SsoEmail { get; set; }
public Contact Contact { get; set; }
}
PayExAgreement的映射文件
public class PayExAgreementMap : EntityBaseMap<PayExAgreement>
{
public PayExAgreementMap()
{
Map(x => x.PayExAgreementRef).Column("PayExAgreementRef").CustomType("AnsiString").Length(50).Not.Nullable();
Map(x => x.PayExPaymentMethod).Column("PayExPaymentMethod").CustomType("AnsiString").Length(50).Not.Nullable();
Map(x => x.PayExMaskedNumber).Column("PayExMaskedNumber").CustomType("AnsiString").Length(50).Not.Nullable();
Map(x => x.PayExPaymentMethodExpireDate).Column("PayExPaymentMethodExpireDate").Not.Nullable();
HasMany(x => x.SubscriptionOrderList).KeyColumn("PayExAgreementRef").PropertyRef("PayExAgreementRef").AsBag().Not.LazyLoad().Cascade.None();
References(x => x.DeptorSso).Column("DeptorSsoId").PropertyRef("SsoId").Not.Nullable().Cascade.None();
和tableSQL
CREATE TABLE [dbo].[PayExAgreement]
(
[Id] INT NOT NULL IDENTITY(1,1),
[DeptorSsoId] UNIQUEIDENTIFIER NOT NULL,
[PayExAgreementRef] VARCHAR(50) NOT NULL,
[PayExMaskedNumber] VARCHAR(50) NOT NULL,
[PayExPaymentMethod] VARCHAR(50) NOT NULL,
[PayExPaymentMethodExpireDate] DATETIME NOT NULL,
CONSTRAINT [PK_PayExAgreement] PRIMARY KEY CLUSTERED ([Id] DESC),
CONSTRAINT [FK_PayExAgreement_User] FOREIGN KEY ([DeptorSsoId]) REFERENCES [User]([SsoId]) ON DELETE NO ACTION ON UPDATE NO ACTION);
我无法弄清楚为什么NHibernate无法识别列的类型(GUID)。 我认为问题是当我尝试制作外键引用时,但解决方案让我感到厌烦。
EDIT !! 这是User类的映射
public class UserMap : EntityBaseMap<User>
{
public UserMap()
{
Map(x => x.SsoEmail).Column("Email").CustomType("AnsiString").Not.Nullable();
Map(x => x.SsoId);
References(x => x.Contact).Column("ContactId").Cascade.SaveUpdate();
}
}