Asp.net 对象引用不是。。。。在_mscustomerRepository.Insert(客户)时;
我正在开发Nopcommerce 2.40。我在项目中创建了新表、它的类和映射 类别代码Asp.net 对象引用不是。。。。在_mscustomerRepository.Insert(客户)时;,asp.net,asp.net-mvc-3,nopcommerce,Asp.net,Asp.net Mvc 3,Nopcommerce,我正在开发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; } publi
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);
}
public部分类MSCustomerMap:EntityTypeConfiguration
{
公共MSCustomerMap()
{
本表为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);
}
}
公共虚拟客户(MSCustomer客户)
{
如果(客户==null)
抛出新的异常(“客户”);
_mscustomerRepository.Insert(客户);
//事件通知
_eventPublisher.EntityUpdate(客户);
}
我已经在数据库中创建了“MScustomer”表,但在插入时抛出错误“对象引用未设置为对象的实例”
在控制器中,我将值分配给属性,并将customer类传递给insert方法。
有什么解决办法吗
它在_mscustomerRepository.Insert(customer)中引发异常
提前感谢是什么让你觉得-你发布的所有代码-实际发生错误的代码不相关?@AntP纠正了问题thanx哪里是
\u mscustomerRepository
初始化了?哦,thanx,我要自杀了,我忘了初始化\u mscustomerRepository