上下文:
我有关系
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中实现多对一?
您应该以这种方式实现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核心关系的快速而又实用的教程”>