我首先遇到了 Code 和生成的 sql 数据库的问题。
是关于公牛和奶牛的应用程序
这是我的课程:
public class Animal : BaseEntity
{
public virtual int? DeathId { get; set; }
public virtual Death Death { get; set; }
public virtual int? SellId { get; set; }
public virtual Sell Sell { get; set; }
}
public class Death : Event
{
public virtual int AnimalId { get; set; }
public virtual Animal Animal { get; set; }
}
public class Sell : Event
{
public virtual int AnimalId { get; set; }
public virtual Animal Animal { get; set; }
}
生成这个 sql 脚本:
create table [dbo].[Animal] (
[Id] [int] not null identity,
[DeathId] [int] null,
[SellId] [int] null,
primary key ([Id])
);
create table [dbo].[Death] (
[Id] [int] not null,
[AnimalId] [int] not null,
primary key ([Id])
);
create table [dbo].[Sell] (
[Id] [int] not null,
[AnimalId] [int] not null,
primary key ([Id])
);
一切正常,但问题在于这些类:
public class Servicie : Event
{
public virtual int MaleId { get; set; }
public virtual Male Male { get; set; }
public virtual int FemaleId { get; set; }
public virtual Female Female { get; set; }
public virtual int? ChildbirthId { get; set; }
public virtual Childbirth Childbirth { get; set; }
}
public class Childbirth : Event
{
public virtual int ServicieId { get; set; }
public virtual Servicie Servicie { get; set; }
public virtual int FemaleId { get; set; }
public virtual Female Female { get; set; }
}
这些类生成这个 Sql 脚本:
create table [dbo].[Service] (
[Id] [int] not null,
[MaleId] [int] not null,
[FemaleId] [int] not null,
[ChildbirthId] [int] null,
primary key ([Id])
);
create table [dbo].[Parto] (
[Id] [int] not null,
[Servicie_Id] [int] not null,
[ServicieId] [int] not null,
[FemaleId] [int] not null,
primary key ([Id])
);
如您所见,自动添加了最后一个“ServicieId”和“Servicie_Id”。
所有都是 1 到 0..1 的关系,我看不出有什么区别,有人可以帮助我吗?