1

nopcommerceDbSetがそのエンティティにどのように使用するかを誰か説明してもらえますか?

NopObjectContext接続文字列で提供されるデータベース内のテーブルをどのように認識しているか知りたいと思っていました。

私の理解では、最初のコードでは、から継承するクラスDbContextの場合、すべてのエンティティに対してゲッターとセッターの DbSet が必要であるということでした。

ただし、これはNopObjectContext. Code First を使用するバージョン 2.6 を使用しています。

4

1 に答える 1

1

Nop.Data.Mapping のクラスは、テーブルとプロパティを定義します。

public partial class CustomerMap : EntityTypeConfiguration<Customer>
{
    public CustomerMap()
    {
        this.ToTable("Customer");
        this.HasKey(c => c.Id);
        this.Property(u => u.Username).HasMaxLength(1000);
        this.Property(u => u.Email).HasMaxLength(1000);
        this.Property(u => u.Password);
        this.Property(c => c.AdminComment).IsMaxLength();
        this.Property(c => c.CheckoutAttributes).IsMaxLength();
        this.Property(c => c.GiftCardCouponCodes).IsMaxLength();

        this.Ignore(u => u.PasswordFormat);
        this.Ignore(c => c.TaxDisplayType);
        this.Ignore(c => c.VatNumberStatus);

        this.HasOptional(c => c.Language)
            .WithMany()
            .HasForeignKey(c => c.LanguageId).WillCascadeOnDelete(false);

        this.HasOptional(c => c.Currency)
            .WithMany()
            .HasForeignKey(c => c.CurrencyId).WillCascadeOnDelete(false);

        this.HasMany(c => c.CustomerRoles)
            .WithMany()
            .Map(m => m.ToTable("Customer_CustomerRole_Mapping"));

        this.HasMany(c => c.DismissedAttributeNotices)
            .WithMany()
            .Map(m => m.ToTable("ProductAttribute_DismissedAttributeNotices"));

        this.HasMany<Address>(c => c.Addresses)
            .WithMany()
            .Map(m => m.ToTable("CustomerAddresses"));
        this.HasOptional<Address>(c => c.BillingAddress);
        this.HasOptional<Address>(c => c.ShippingAddress);
        this.HasOptional<Customer>(c => c.SelectedSalesRep);
    }
}

Customer は Nop.Core.Domain.Customers.Customer.cs で定義されます。そのすべてのプロパティがテーブルにマップされます。ここで追加する必要があるのは、使用するテーブル、無視するプロパティ、関係、およびフィールドのプロパティ (文字列の長さまたは精度) だけです。

于 2012-12-13T13:29:08.637 に答える