.net 2.0 프로젝트가 있고 Entity Framework Core 2.0을 사용하고 있습니다. 상속이있는 엔터티를 매핑하려고하는데이 상속이 상속되었습니다.상속을 사용하여 엔터티를 매핑하는 방법 - Entity Framework 2.0 2.0
내가[Domain.Project]
에 매핑 할
내 엔티티 :
public class Customer : BaseEntity
{
public Customer(Name name, DateTime? birthDay, Email email, string password, List<CreditDebitCard> creditDebitCards = null)
{
CreationDate = DateTime.Now;
Name = name;
BirthDay = birthDay;
Email = email;
Password = password;
_CreditDebitCards = creditDebitCards ?? new List<CreditDebitCard>();
}
[Fields...]
[Properties...]
[Methods...]
}
내 BaseEntity
클래스 [Domain.Project]
의 :
public abstract class BaseEntity : Notifiable
{
public BaseEntity()
{
CreationDate = DateTime.Now;
IsActive = true;
}
[Fields...]
[Properties...]
[Methods...]
}
내 Notifiable
클래스 [Shared.Project]
에서 (보면, 그것은 Notification
유형의 목록을 가지고) :
public abstract class Notifiable
{
private readonly List<Notification> _notifications;
protected Notifiable() { _notifications = new List<Notification>(); }
public IReadOnlyCollection<Notification> Notifications => _notifications;
[Methods...]
}
내 Notification
클래스 [Shared.Project]
에 :
public class Notification
{
public Notification(string property, string message)
{
Property = property;
Message = message;
}
public string Property { get; private set; }
public string Message { get; private set; }
}
[Infra.Project]
에서
내 엔티티 프레임 워크 컨텍스트 클래스 :
public class MoFomeDataContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(Runtime.ConnectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CreditDebitCard>().Map();
}
}
내 Mapping
클래스는입니다.: 내가 마이그레이션을 추가하려고하면
public static class CustomerMap
{
public static EntityTypeBuilder<Customer> Map(this EntityTypeBuilder<Customer> cfg)
{
cfg.ToTable("Customer");
cfg.HasKey(x => x.Id);
cfg.Property(x => x.BirthDay).IsRequired();
cfg.OwnsOne(x => x.Email);
cfg.OwnsOne(x => x.Name);
cfg.HasMany(x => x.CreditDebitCards);
return cfg;
}
}
,이 오류가 얻을 : 내 상황에 매핑 된
The entity type 'Notification' requires a primary key to be defined.
그러나 어느 것도 Notification
클래스와 어느 것도 Notifiable
클래스를, 그들은 매핑되지 않아야합니다 .
나는 그물 전체 프레임 워크에서 할 그것은 here는 EF 코어가 발견 관례 그물 전체 프레임 워크 코드