Connecter.cs
public virtual DbSet<Guild> Guild { get; set; }
public virtual DbSet<Role> Role { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Guild>(entity => {
entity.HasKey(e => e.Gid)
.HasName("PRIMARY");
entity.HasIndex(e => e.Gid)
.HasName("gid_UNIQUE")
.IsUnique();
entity.Property(e => e.Gid)
.HasColumnName("gid")
.HasColumnType("bigint(20) unsigned");
});
modelBuilder.Entity<Role>(entity => {
entity.HasKey(e => e.Gid);
entity.HasIndex(e => e.Gid)
.HasName("gid");
entity.Property(e => e.Gid)
.HasColumnName("gid")
.HasColumnType("bigint(20) unsigned");
entity.HasOne(d => d.Guild)
.WithMany(p => p.Role)
.HasForeignKey(d => d.Gid)
.HasConstraintName("role_ibfk_1");
});
}
Guild.cs
public Guild() // ef core auto create
{
Role = new HashSet<Role>();
}
public ulong Gid { get; set; }
[ForeignKey("Gid")]
public virtual ICollection<Role> Role { get; set; }
Role.cs
public ulong Gid { get; set; }
public virtual Guild Guild { get; set; }
Main.cs
public static void Main(string[] args)
{
var context = new Connector();
var single = context.Guild.Single(e => e.Gid == 442018515965313024);
Trace.WriteLine(single.Role.Count); // Result : 0
}
Очевидно, что в схемах есть значения, соответствующие "Gid" (Guild, Role). Однако в отношениях нет никакой ценности. Я сделал что-то не так?