gpt4 book ai didi

entity-framework-core - 具有相同名称的查询类型已存在

转载 作者:行者123 更新时间:2023-12-03 15:44:13 25 4
gpt4 key购买 nike

The entity type 'MyType' cannot be added to the model because a query type with the same name already exists.



public class MyContext : DbContext
{
public DbQuery<MyType> MyTypes { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//Exception is thrown here

//needed b/c table is not named MyTypes
modelBuilder.Entity<MyType>()
.ToTable("MyType");
}
}

最佳答案

DbQuery更改为DbSetQuery Types用于 View among other things

public class MyContext : DbContext
{
//DbSet not DbQuery
public DbSet<MyType> MyTypes { get; set; }
}

关于entity-framework-core - 具有相同名称的查询类型已存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57205049/

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