Up
Up
Explore posts from servers
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
update: solution was to enable lazy loading proxies via Microsoft.EntityFrameworkCore.Proxies, and mark all my navigation properties as virtual.
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
any other ideas @jcotton42?
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
no change
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
update: tried it with implicit properties and even deleted + re-seeded the DB.
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
yes
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
here's how I assign those relations:
modelBuilder.Entity<Mod>().HasIndex(it => it.Slug).IsUnique();
modelBuilder.Entity<Mod>().HasOne(it => it.Meta).WithOne(it => it.Mod).HasForeignKey<ModMetadata>(it => it.ModId);
modelBuilder.Entity<Mod>().HasMany(it => it.PlatformIDs).WithOne(it => it.Mod).HasForeignKey(it => it.ModId);
modelBuilder.Entity<ModSupportedPlatform>().HasOne(it => it.Platform).WithMany().HasForeignKey(it => it.PlatformId).IsRequired();
modelBuilder.Entity<ModSupportedPlatform>().HasKey(it => new {it.PlatformId, it.PlatformKey});
modelBuilder.Entity<Mod>().HasIndex(it => it.Slug).IsUnique();
modelBuilder.Entity<Mod>().HasOne(it => it.Meta).WithOne(it => it.Mod).HasForeignKey<ModMetadata>(it => it.ModId);
modelBuilder.Entity<Mod>().HasMany(it => it.PlatformIDs).WithOne(it => it.Mod).HasForeignKey(it => it.ModId);
modelBuilder.Entity<ModSupportedPlatform>().HasOne(it => it.Platform).WithMany().HasForeignKey(it => it.PlatformId).IsRequired();
modelBuilder.Entity<ModSupportedPlatform>().HasKey(it => new {it.PlatformId, it.PlatformKey});
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
[Table("mods")]
public class Mod : BaseModel
{
public string Slug { get; set; } = null!;

public ModMetadata Meta { get; set; } = null!;

public ICollection<ModSupportedPlatform> PlatformIDs { get; set; } = new List<ModSupportedPlatform>();
public ICollection<McVersion> SupportedVersions { get; set; } = new List<McVersion>();

[GraphField("supportedPlatforms")]
public IEnumerable<Platform> GetSupportedPlatforms()
{
return PlatformIDs.Select(it => it.Platform).AsEnumerable();
}
}
[Table("mods")]
public class Mod : BaseModel
{
public string Slug { get; set; } = null!;

public ModMetadata Meta { get; set; } = null!;

public ICollection<ModSupportedPlatform> PlatformIDs { get; set; } = new List<ModSupportedPlatform>();
public ICollection<McVersion> SupportedVersions { get; set; } = new List<McVersion>();

[GraphField("supportedPlatforms")]
public IEnumerable<Platform> GetSupportedPlatforms()
{
return PlatformIDs.Select(it => it.Platform).AsEnumerable();
}
}
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
however, I am unable to retrieve the supported platforms it seems
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
okay, I've redone the DB and am now able to insert data properly.
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
because that is what I've mainly been using the fluent api for
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
so how do I use conventions to add constraints?
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
ik but more like, I haven't needed to add/remove yet
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
I haven't gotten around to that yet, haha
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
well it never complained about it 😅
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
what else would I use?
43 replies
CC#
Created by Up on 8/11/2023 in #help
✅ EF Core Relations don't seem to work properly
..which means serializing it into a separate table
43 replies