简体   繁体   English

EntityFramework:使用EntityTypeConfiguration映射具有列表的类

[英]EntityFramework: Using EntityTypeConfiguration to map a class that has a List

I have this class: 我有这个课:

public class RecentlyViewedProducts : BaseEntity
{
    public int CustomerId { get; set; }
    public List<int> ProductId { get; set; }
}

How to use EntityTypeConfiguration<TEntityType>.HasKey<TKey> method to say that the generated table will have a composite key (CustomerId, ProductId ) ? 如何使用EntityTypeConfiguration<TEntityType>.HasKey<TKey>方法说生成的表将具有复合键(CustomerId, ProductId )

That means I want to get the "rows per customer" as the Count of the related List ? 这意味着我想获取“每位客户的行数”作为相关List计数

You can make a composite key by including this in your mapping: 您可以通过将其包含在映射中来制作组合键:

// Primary Key
HasKey(e => new { e.CustomerId, e.ProductId});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM