我正在开发 Nopcommerce 2.40。我在项目中创建了新表、它的类和映射
班级代码
namespace Nop.Core.Domain.Customers
{
public partial class MSCustomer:BaseEntity
{
public virtual string Name { get; set; }
public virtual string Email { get; set; }
public virtual string Address { get; set; }
public virtual string PhoneNumber { get; set; }
public virtual string ComapnyName { get; set; }
public virtual DateTime CreatedOnUtc { get; set; }
}
}
下面是我的映射
public partial class MSCustomerMap : EntityTypeConfiguration<MSCustomer>
{
public MSCustomerMap()
{
this.ToTable("MSCustomer");
this.HasKey(c => c.Id);
this.Property(u => u.Name).HasMaxLength(1000);
this.Property(u => u.Address).HasMaxLength(1000);
this.Property(u => u.Email).HasMaxLength(100);
this.Property(c => c.PhoneNumber).HasMaxLength(100);
this.Property(c => c.CompanyName).HasMaxLength(100);
}
}
public virtual void CreateCustomer(MSCustomer customer)
{
if (customer == null)
throw new ArgumentNullException("cutomer");
_mscustomerRepository.Insert(customer);
//event notification
_eventPublisher.EntityUpdated(customer);
}
我在数据库中创建了“MScustomer”表,但在插入时抛出错误“对象引用未设置为对象的实例”。
在控制器中,我将值分配给属性并将客户类传递给插入方法。有没有什么解决办法。
它在 _mscustomerRepository.Insert(customer); 处引发异常
提前致谢