如何具有多对一关系EF?

问题描述 投票:0回答:1

上下文:

我有关系

class Service {
   public virtual int Sequencial { get; set; }
   public virtual string Name { get; set; }
   public virtual ServiceType Type { get; set; }
   ...
}

class ServiceType {
   public virtual int Sequencial { get; set; }
   public virtual string Name { get; set; }
}

在NHibernate类中看起来像这样

Id(s => s.Sequencial,“ SERVICE_ID”)。GeneratedBy.Sequence(“ SQ_SERVICE_ID”);引用(s => s.ServiceType,“ SERVICE_TYPE_ID”);地图(a => a.Nome,“ SERVICE_NAME”);...

如何实现References(s => s.ServiceType,“ SERVICE_TYPE_ID”),换句话说,如何在EF中实现多对一?

c# entity-framework nhibernate entity-framework-core
1个回答
0
投票

您应该以这种方式实现ServiceType类:

class Service {
   public virtual int Sequencial { get; set; }
   public virtual string Name { get; set; }
   public virtual ServiceType Type { get; set; }
   ...
}

class ServiceType {
   public virtual int Sequencial { get; set; }
   public virtual string Name { get; set; }
   public virtual ICollection<Service> Services { get; set; } // Add this string
}

您可以在此article中找到有关EF核心关系的快速而又实用的教程”>

© www.soinside.com 2019 - 2024. All rights reserved.