このような質問が提起されたのを見たことがありません。そこで、EF 流暢な API 開発者と nopcommerce プラグイン開発者向けに作成しました。
これが私がやろうとしていることです:
製品エンティティがあり、データベースを生成するために EF で使用できます。元のクラスを変更せずに製品エンティティを拡張したい。それで、私は部分クラスを使用しようとしました。コードは次のようになります。
namespace Nop.Core.Domain.Catalog
{
/// <summary>
/// Represents a product
/// </summary>
public partial class Product : BaseEntity, ILocalizedEntity, ISlugSupported, IAclSupported, IStoreMappingSupported
{
//some fields here.
public int ProductTypeId { get; set; }
//.....
}
}
クラスを次のように拡張すると、次のようになります。
namespace Nop.Core.Domain.Catalog
{
public partial class Product : BaseEntity
{
public int RestaurantId { get; set; }
public virtual Restaurant BelongRestaurant { get; set; }
}
}
エラーがスローされます。
タイプ 'Nop.Core.Domain.Catalog.Product' とタイプ 'Nop.Core.Domain.Catalog.Product' は両方とも 'Product' という単純な名前を持っているため、同じモデルでは使用できません。特定のモデルのすべての型には、一意の単純名が必要です。'NotMappedAttribute' を使用するか、Code First fluent API で Ignore を呼び出して、モデルからプロパティまたは型を明示的に除外します。
私のマッピングファイルは次のようになります:
namespace Nop.Plugin.Misc.Plugin
{
public partial class ProductMap : EntityTypeConfiguration<Nop.Core.Domain.Catalog.Product>
{
public ProductMap()
{
//Table
this.ToTable(Settings.DATABASE_TABLE_NAME);
//Primary Key
this.HasKey(t => t.Id);
//Property
this.Property(t => t.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.HasRequired(p => p.BelongRestaurant)
.WithMany(r => r.Menu)
.HasForeignKey(p => p.RestaurantId)
.WillCascadeOnDelete(false);
}
}
}
誰でも助けてもらえますか?