c# - 缺少 RelationalTypeMapping 实体框架核心
问题描述
我已经使用流利的模型构建器手动设置了我的实体框架映射,并且在我查询时一切正常,但是在尝试创建实体时,这就是我得到的:
值不能为空。参数名称:relationalTypeMapping
这是堆栈跟踪:
在 Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T 值,字符串参数名称)
在 Microsoft.EntityFrameworkCore.Storage.Internal.TypeMappedRelationalParameter..ctor(字符串 invariantName,字符串名称,RelationalTypeMapping 关系类型映射,Nullable 2 参数,CancellationToken 取消令牌)在 Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IReadOnlyList 3.CreateAsync(TDto dto ) 上的 Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func 4 verifySucceeded, CancellationToken cancelToken) )1 nullable)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalParameterBuilder.AddParameter(String invariantName, String name, IProperty property)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommandBuilderExtensions.AddParameter(IRelationalCommandBuilder commandBuilder, String invariantName, String name, IProperty property) at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.CreateStoreCommand() at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(DbContext _, ValueTuple4 operation, Func
1 entriesToSave, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at FastTrack.EntityFramework.Services.EntityFrameworkService
这是我的映射代码:
builder.Entity(typeof(Page), b =>
{
b.HasOne(typeof(Site))
.WithMany()
.HasForeignKey("SiteId")
.IsRequired();
});
builder.Entity<Site>()
.HasMany(x => x.Pages)
.WithOne(x => x.Site)
.HasForeignKey("SiteId")
.IsRequired();
以下是实体:
public class Site
{
public int Id {get; set;}
public string Name {get; set;}
public IList<Page> Pages { get; set; }
public string Domain { get; set; }
}
public class Page
{
public int Id {get; set;}
public string Name {get; set;}
public IList<PageSelector> PageSelectors { get; set; }
public string Path { get; set; }
public Site Site { get; set; }
[ForeignKey("Site")]
public int SiteId { get; set; }
}
什么可能导致这种情况发生?映射似乎设置正确,一切正常,直到我想在数据库中插入一些东西。
解决方案
推荐阅读
- database - 我无法从 VB.net 的 MS 访问数据库中删除一行
- python - Python二叉树中序遍历生成器函数
- jquery - jQuery:处理来自更改选择的事件
- flutter - 从firebase获取数据后如何将数据放入Hivedb?并从 Hivedb 访问数据 1 小时?
- javascript - 在嵌套的对象数组中查找数组
- android - '设置为墙纸和锁屏' PWA android
- android - 当我使用 Coroutines 向数据库添加新项目时,Room 数据库如何在 UI 中更新我的 RecyclerView?
- r - 如何在 googlesheet 中追加新数据
- google-apps-script - 在谷歌脚本项目中搜索触发器
- python - Python asyncio SSL 传输未关闭