如果没有DBSET属性,该表是在数据库内存中创建的吗?

发布于 2025-02-03 08:23:17 字数 1596 浏览 2 评论 0原文

这是我的dbcontext

public class MyDatabaseContext : DbContext
{
    public MyDatabaseContext(DbContextOptions<MyDatabaseContext> options) : base(options)
    {

    }
    public DbSet<Buyer> Buyers { get; set; }
    public DbSet<Sale> Sales { get; set; }
    public DbSet<Product> Products { get; set; }
    public DbSet<SalesPoint> SalesPoints { get; set; }
    //public DbSet<ProvidedProduct> ProvidedProducts { get; set; }
}

这是我的销售类别类,

public partial class SalesPoint
{
    public int Id { get; set; }
    [Required]
    public string Name { get; set; }
    public List<ProvidedProduct> ProvidedProducts { get; set; }
}

这是我的提供产品类

public class ProvidedProduct
{
   
    public int Id { get; set; }
    public int ProductId { get; set; }
    public int ProductQuantity { get; set; }
}

,所以问题是,在数据库中存储了Table Profoduct吗?因为当我在表销售中删除一行并添加一个新的行时,元素ID并非来自最后一个提供的产品元素,而是来自已删除的提供产品元素。也就是说,那是:

{
"id": 1,
"name": "OZON",
"providedProducts": [
  {
    "id": 1,
    "productId": 2,
    "productQuantity": 2
  },
  {
    "id": 2,
    "productId": 3,
    "productQuantity": 1
  }
]
},

然后删除此表行并添加一个新的一行

    {
"id": 1,
"name": "OZON",
"providedProducts": [
  {
    "id": 3,
    "productId": 2,
    "productQuantity": 2
  },
  {
    "id": 4,
    "productId": 3,
    "productQuantity": 1
  }
]
},

,而元素ID等于3 4,而不是1 2,因此在我看来,该表提供的产品仍然存储在数据库中,尽管“ //公共DBSET提供的产品{get;};告诉我谁知道。多谢。世界和平。 我希望我能正确提出我的想法,五月Google翻译会帮助我

This is my DbContext

public class MyDatabaseContext : DbContext
{
    public MyDatabaseContext(DbContextOptions<MyDatabaseContext> options) : base(options)
    {

    }
    public DbSet<Buyer> Buyers { get; set; }
    public DbSet<Sale> Sales { get; set; }
    public DbSet<Product> Products { get; set; }
    public DbSet<SalesPoint> SalesPoints { get; set; }
    //public DbSet<ProvidedProduct> ProvidedProducts { get; set; }
}

This is my SalesPoints class

public partial class SalesPoint
{
    public int Id { get; set; }
    [Required]
    public string Name { get; set; }
    public List<ProvidedProduct> ProvidedProducts { get; set; }
}

This is my ProvidedProduct class

public class ProvidedProduct
{
   
    public int Id { get; set; }
    public int ProductId { get; set; }
    public int ProductQuantity { get; set; }
}

So the question is, is table ProvidedProduct stored in the database? For when I delete a row in table SalesPoints, and add a new one, the element ids do not come from the last ProvidedProduct element, but from the deleted ProvidedProduct element. That is, it was:

{
"id": 1,
"name": "OZON",
"providedProducts": [
  {
    "id": 1,
    "productId": 2,
    "productQuantity": 2
  },
  {
    "id": 2,
    "productId": 3,
    "productQuantity": 1
  }
]
},

then delete this table row and add a new one

    {
"id": 1,
"name": "OZON",
"providedProducts": [
  {
    "id": 3,
    "productId": 2,
    "productQuantity": 2
  },
  {
    "id": 4,
    "productId": 3,
    "productQuantity": 1
  }
]
},

and the element id equals 3 4, not 1 2, so it seems to me that the table ProvidedProducts is still stored in the database, although the "//public DbSet ProvidedProducts { get; set; }" property is commented out. Tell me who knows. Thanks a lot. Peace to the world.
I hope I formulated my idea correctly, may google translate help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

李白 2025-02-10 08:23:17

DBContext类(mydatabasecontext)中的已声明的DBSET将是所有表。这意味着您应该从销售类别中删除提供的产品,并在mydatabasecontext类中取消注释的DBSET。

The declared DbSets within your DbContext Class (MyDatabaseContext) will be all the tables. This means you should remove ProvidedProducts from SalesPoint class and uncomment the commented DbSet in your MyDatabaseContext class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文