gpt4 book ai didi

entity-framework-6 - EntityFramework - 将 WithRequired 移植到 EF Core

转载 作者:行者123 更新时间:2023-12-04 07:52:54 27 4
gpt4 key购买 nike

我正在将应用程序从 MVC5/EF6 移植到 MVC6/EF7,但此特定行有问题:

        modelBuilder.Entity<Client>().HasMany(c => c.Payments).WithRequired(e => e.Client).WillCascadeOnDelete(false);

显然,WillCascadeOnDelete 已转换为 OnDelete,并将 restrict 作为参数,但我找不到关于“WithRequired”部分的任何文档,该部分在 EF7 中也已消失。具有“WithOne”相同的影响还是我在这里完全错了:

        modelBuilder.Entity<Client>().HasMany(c => c.Payments).WithOne(e => e.Client).OnDelete(Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Restrict);

最佳答案

你在这两种情况下都是正确的。这是一个详细的帖子... http://www.mikee.se/posts/migrating_from_ef6_to_ef_core

Typically these mappings would change from this in EF6.

x.Entity<Company>()
.HasMany(c => c.StatementOfEarnings)
.WithRequired(e => e.Company)
.WillCascadeOnDelete(false);

To this in EF Core

x.Entity<Company>()
.HasMany(c => c.StatementOfEarnings)
.WithOne(e => e.Company)
.OnDelete(DeleteBehavior.Restrict);

关于entity-framework-6 - EntityFramework - 将 WithRequired 移植到 EF Core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41245384/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com