I am working on Fluent Nhibernate and I am getting the following error:
"Cannot insert the value NULL into column 'EmailAccountId', table 'NopCommerceNew123.dbo.QueuedEmail'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."} could not insert: [Nop.Core.Domain.Messages.QueuedEmail][SQL: INSERT INTO QueuedEmail ([Priority], [From], FromName, [To], ToName, CC, Bcc, [Subject], Body, AttachmentFilePath, AttachmentFileName, CreatedOnUtc, SentTries, SentOnUtc, EmailAccountId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()]
Please let me know about the error in this.Thanks.
Here Are My Classes and mappings:
QueueEmail.cs
public partial class QueuedEmail : BaseEntity
{
/// <summary>
/// Gets or sets the priority
/// </summary>
public virtual int Priority { get; set; }
/// <summary>
/// Gets or sets the From property
/// </summary>
public virtual string From { get; set; }
/// <summary>
/// Gets or sets the FromName property
/// </summary>
public virtual string FromName { get; set; }
/// <summary>
/// Gets or sets the To property
/// </summary>
public virtual string To { get; set; }
/// <summary>
/// Gets or sets the ToName property
/// </summary>
public virtual string ToName { get; set; }
/// <summary>
/// Gets or sets the CC
/// </summary>
public virtual string CC { get; set; }
/// <summary>
/// Gets or sets the Bcc
/// </summary>
public virtual string Bcc { get; set; }
/// <summary>
/// Gets or sets the subject
/// </summary>
public virtual string Subject { get; set; }
/// <summary>
/// Gets or sets the body
/// </summary>
public virtual string Body { get; set; }
/// <summary>
/// Gets or sets the attachment file path (full file path)
/// </summary>
public virtual string AttachmentFilePath { get; set; }
/// <summary>
/// Gets or sets the attachment file name. If specified, then this file name will be sent to a recipient. Otherwise, "AttachmentFilePath" name will be used.
/// </summary>
public virtual string AttachmentFileName { get; set; }
/// <summary>
/// Gets or sets the date and time of item creation in UTC
/// </summary>
public virtual DateTime CreatedOnUtc { get; set; }
/// <summary>
/// Gets or sets the send tries
/// </summary>
public virtual int SentTries { get; set; }
/// <summary>
/// Gets or sets the sent date and time
/// </summary>
public virtual DateTime? SentOnUtc { get; set; }
/// <summary>
/// Gets or sets the used email account identifier
/// </summary>
public virtual int EmailAccountId { get; set; }
/// <summary>
/// Gets the email account
/// </summary>
public virtual EmailAccount EmailAccount { get; set; }
}
EmailAccount.cs
public partial class EmailAccount : BaseEntity
{
/// <summary>
/// Gets or sets an email address
/// </summary>
public virtual string Email { get; set; }
/// <summary>
/// Gets or sets an email display name
/// </summary>
public virtual string DisplayName { get; set; }
/// <summary>
/// Gets or sets an email host
/// </summary>
public virtual string Host { get; set; }
/// <summary>
/// Gets or sets an email port
/// </summary>
public virtual int Port { get; set; }
/// <summary>
/// Gets or sets an email user name
/// </summary>
public virtual string Username { get; set; }
/// <summary>
/// Gets or sets an email password
/// </summary>
public virtual string Password { get; set; }
/// <summary>
/// Gets or sets a value that controls whether the SmtpClient uses Secure Sockets Layer (SSL) to encrypt the connection
/// </summary>
public virtual bool EnableSsl { get; set; }
/// <summary>
/// Gets or sets a value that controls whether the default system credentials of the application are sent with requests.
/// </summary>
public virtual bool UseDefaultCredentials { get; set; }
public virtual ICollection<QueuedEmail> QueueEmail { get; set; }
/// <summary>
/// Gets a friendly email account name
/// </summary>
public virtual string FriendlyName
{
get
{
if (!String.IsNullOrWhiteSpace(this.DisplayName))
return this.Email + " (" + this.DisplayName + ")";
return this.Email;
}
}
QueuedEmailMap.cs:
public class QueuedEmailMap : ClassMap<QueuedEmail>
{
public QueuedEmailMap()
{
Table("QueuedEmail");
LazyLoad();
Id(x => x.Id).GeneratedBy.Identity().Column("Id");
Map(x => x.Priority).Column("[Priority]").Not.Nullable().Precision(10);
Map(x => x.From).Column("[From]").Not.Nullable().Length(500);
Map(x => x.FromName).Column("FromName").Length(500);
Map(x => x.To).Column("[To]").Not.Nullable().Length(500);
Map(x => x.ToName).Column("ToName").Length(500);
Map(x => x.CC).Column("CC").Length(500);
Map(x => x.Bcc).Column("Bcc").Length(500);
Map(x => x.Subject).Column("[Subject]").Length(1000);
Map(x => x.Body).Column("Body");
Map(x => x.AttachmentFilePath).Column("AttachmentFilePath");
Map(x => x.AttachmentFileName).Column("AttachmentFileName");
Map(x => x.CreatedOnUtc).Column("CreatedOnUtc").Not.Nullable();
Map(x => x.SentTries).Column("SentTries").Not.Nullable().Precision(10);
Map(x => x.SentOnUtc).Column("SentOnUtc");
//References(x => x.EmailAccount).Class<EmailAccount>().Columns("EmailAccountId");
References(x => x.EmailAccount).Column("EmailAccountId").Not.Nullable().Cascade.All();
}
}
EmailAccountMap.cs:
public class EmailAccountMap : ClassMap<EmailAccount>
{
public EmailAccountMap()
{ Table("EmailAccount");
LazyLoad();
Id(x => x.Id).GeneratedBy.Identity().Column("Id");
Map(x => x.Email).Column("Email").Not.Nullable().Length(255);
Map(x => x.DisplayName).Column("DisplayName").Length(255);
Map(x => x.Host).Column("Host").Not.Nullable().Length(255);
Map(x => x.Port).Column("Port").Not.Nullable().Precision(10);
Map(x => x.Username).Column("Username").Not.Nullable().Length(255);
Map(x => x.Password).Column("Password").Not.Nullable().Length(255);
Map(x => x.EnableSsl).Column("EnableSsl").Not.Nullable();
Map(x => x.UseDefaultCredentials).Column("UseDefaultCredentials").Not.Nullable();
}
}