EF提供以下我的号码

时间:2015-09-19 21:13:17

标签: c# entity-framework

我得到的产品从1到10 Insted 1-4和7到12

db.product.Add(new Product() {Id=1 ,ProductType = 0,Active = false,});
db.product.Add(new Product() { Id = 2, ProductType = 0, Active = false, });
db.product.Add(new Product() { Id = 3, ProductType = 0, Active = false, });
db.product.Add(new Product() { Id = 4, ProductType = 0, Active = false, });
//  db.product.Add(new Product() { Id = 5, ProductType = 1, Active = false,SensorValue = 0});
//   db.product.Add(new Product() { Id = 6, ProductType = 2, Active = false, SensorValue = 0 });
db.product.Add(new Product() { Id = 7, ProductType = 3, Active = false, SensorValue = 0 });
db.product.Add(new Product() { Id = 8, ProductType = 4, Active = false, SensorValue = 0 });
db.product.Add(new Product() { Id = 9, ProductType = 5, Active = false, SensorValue = 0 });
db.product.Add(new Product() { Id = 10, ProductType = 6, Active = false});
db.product.Add(new Product() { Id = 11, ProductType = 7, Active = false });
db.product.Add(new Product() { Id = 12, ProductType = 8, Active = false });

1 个答案:

答案 0 :(得分:1)

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]

public int Id { get; set; }