私は 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); で例外をスローします。
前もって感謝します