如果没有DBSET属性,该表是在数据库内存中创建的吗?
这是我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.