-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data Seeding: Add support for navigations #10000
Comments
5 figures |
This was completely not on purpose. It just happens to be that I had to file 5 issues today. |
I think this is the first repo in the 'aspnet' org with this number of issues. Do we celebrate? |
Is there really no workaround till you're busy implementing? |
@iamkarlson The workaround is to specify the foreign key values. See https://docs.microsoft.com/en-us/ef/core/modeling/data-seeding |
@AndriySvyryd Thanks, actually I did how you said but the problem was that even an empty list raises such error. I had to manually set it to null after my lazy loading. |
@iamkarlson that sounds like a different issue. Could you file it separately and include a small repro? |
Do you mind if I attach #12688 to that, just to make sure it won't be missed when you complete this task? |
I still don't know what is the scenario in #12688 |
Guys, any ideas about a timeline for this feature? |
It's in the backlog, so it probably will be done after 2019. Remember to vote 👍 for features you'd like us to prioritize. |
I find this issue very annoying, I have an owned entity that I want to set its property at the parent to auto-initialize if null: class Contact
{
public int Id { get; set; }
Address _Address;
public Address Address
{
get => _Address ??= new Address { /*tried this too*/ ContactId = Id };
set => _Address = value;
}
} When adding the parent as
Would love to see this functionality enabled, so we can use auto-initialized properties in entities. |
Solution was adding the parent entity as anonymous class: modelBuilder.Entity<Contact>().HasData(new { ... }); |
is there any update on this feature? Seems for me like there's not much sense in Seeding mechanism if we need to use anonymous classes for all owned properties. It's much easier to use oldfashioned manual seeding on startup, isn't it? |
@Unders0n While data in the model can be useful, I would agree that manual seeding on startup is often a better approach. |
Any update on when you plan to add this? For configuration data that should be only changed with the source code having data seeding is very useful, but having to depend on anonymous types is error prone and less readable |
@ggonzalez94 This issue is in the Backlog milestone. This means that it is not planned for the next release (EF Core 5.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. |
Any workaround for optional relationships? |
Seeding Owned Entities gets even uglier if you have to implement the hack to allow composite indexes comprised of properties from both the owning and owned entity types. Now I have to seed the shadow property(ies) that were created for the indexing hack. OwnedNavigationBuilder<SoftwareRelease, SemanticVersion> softwareReleaseNavigationBuilder = null!;
modelBuilder.Entity<SoftwareRelease>()
.OwnsOne(p => p.SemanticVersion,
oe =>
{
// Workaround for the fact that owned entities cannot currently be used in a composite key with properties of the owning entity.
// Shadow the owning entity property into the owned entity.
// https://github.com/dotnet/efcore/issues/11336
oe.Property<string>("ShadowProductDeliveryGroupCode")
.HasColumnName("product_delivery_group_code");
oe.HasIndex("ShadowProductDeliveryGroupCode", "Major", "Minor", "Patch");
softwareReleaseNavigationBuilder = oe;
}); OwnedNavigationBuilder later used to seed data. private static void SeedSoftwareReleaseVersions(OwnedNavigationBuilder<SoftwareRelease,SemanticVersion> builder)
{
builder
.HasData(
// When seeding Owned entities, we have to use an anonymous type because the primary key field is a shadow field
CreateSoftwareReleaseVersion(1, "6.0.17", "code1"),
CreateSoftwareReleaseVersion(2, "6.0.18", "code1"),
CreateSoftwareReleaseVersion(3, "9.9.5", "code2"),
CreateSoftwareReleaseVersion(4, "9.9.6", "code2"),
CreateSoftwareReleaseVersion(5, "9.9.7", "code2"),
CreateSoftwareReleaseVersion(6, "9.9.8", "code2")
);
}
private static dynamic CreateSoftwareReleaseVersion(long softwareReleaseId, string versionDisplay,string shadowProductDeliveryGroupCode)
{
SemanticVersion version = new(versionDisplay);
return new
{
version.Major,
version.Minor,
version.Patch,
SoftwareReleaseId = softwareReleaseId,
version.Display,
ShadowProductDeliveryGroupCode = shadowProductDeliveryGroupCode
};
} References: |
So many github issues linked to this, and depend on this. Any update on this? |
This depends on #9914
The text was updated successfully, but these errors were encountered: