【问题标题】:NopCommerce add new table - invalid column name 'Product_Id1'NopCommerce 添加新表 - 无效的列名“Product_Id1”
【发布时间】:2014-10-04 12:13:22
【问题描述】:

我正在考虑在 mycommerce 引擎中添加一个新表;

关系

[Product] 1..* [Awards]

代码文件:

public partial class Awards : BaseEntity, ILocalizedEntity
{
    public virtual Product Product { get; set; }

    public string AwardDescription { get; set; }
    public Guid AwardGUID { get; set; }
    public int Product_Id { get; set; }
}

public partial class AwardsMap : EntityTypeConfiguration<Awards>
{
    public AwardsMap()
    {
        this.ToTable("Awards");
        this.HasKey(p => p.Id);

        this.Property(p => p.AwardGUID).IsOptional();
        this.Property(p => p.AwardDescription).IsOptional();

        this.HasRequired(p => p.Product)
            .WithMany(pt => pt.ProductAwards)
            .Map(m => m.ToTable("Awards"));
    }
}


public partial interface IAwardsService
{
    void DeleteAwards(Awards Awards);
    IList<Awards> GetAllAwardss();
    Awards GetAwardsById(int AwardsId);
    void InsertAwards(Awards Awards);
    void UpdateAwards(Awards Awards);
}

还有实现IAwardsService接口的AwardsService.cs类(与ProductTagService.cs一样)

Product.cs代码sn-p:

private ICollection<Awards> _awards;
public virtual ICollection<Awards> ProductAwards
{
    get { return _awards ?? (_awards = new List<Awards>()); }
    protected set { _awards = value; }
}

但每次我从数据库加载产品并尝试加载 ProductAwards 属性时,我都会收到错误

Invalid column name 'Product_Id1'.
Invalid column name 'Product_Id1'.

发生了什么事?

编辑

我看到了Customer, CustomerAddress, Address 表,我已经修改了我的类,使其看起来与那些相同,现在它可以工作了。

【问题讨论】:

    标签: c# asp.net-mvc nopcommerce


    【解决方案1】:

    请检查映射表的列名是否与您的类中定义的完全相同。

    这里看起来像冲突,因为它抛出错误 Invalid column name 'Product_Id1' 并且你的类中的属性名称是 Product_Id

    【讨论】:

    • 在我的表中,我有以下列:[Id]、[AwardDescription]、[AwardGUID]、[Product_Id]。它们与 Award.cs 类中的相同
    • 那么为什么错误是 Invalid column name 'Product_Id1'。
    • 这就是我提出问题的原因。我的数据库或项目中不存在 Product_Id1 列或名称
    【解决方案2】:

    在奖项地图中:

    替换这个:

    this.HasRequired(p => p.Product)
                .WithMany(pt => pt.ProductAwards)
                .Map(m => m.ToTable("Awards"));
    

    用这个:

    this.HasRequired(p => p.Product)
                .WithMany(pt => pt.ProductAwards)
                .HasForeignKey(p => p.Product_Id);
    

    【讨论】:

      猜你喜欢
      • 2017-04-24
      • 2012-05-07
      • 2017-12-05
      • 2014-04-04
      • 2012-04-12
      • 1970-01-01
      • 2014-07-03
      • 1970-01-01
      相关资源
      最近更新 更多