我突然有了这种奇怪的行为(我在版本控制(tfs)中比较了我的文件,以确保我没有更改任何内容,也没有发现任何不同之处)。
我在我的数据库中植入了一些元数据,我发现它有一种我从未见过的非常奇怪的行为。我插入了一个实体“产品”,它插入了这个实体
两次
,第一个insert是正确的,并且具有它应该具有的所有内容,另一个具有空属性(字符串值),但某些(如datetimes)具有值。
我完全不知道为什么会发生这种情况,它是在我调用base.Seed(ctx)时发生的;方法,我确信,因为在此之后,我在Web应用到达任何其他位置之前停止了它。
此实体产品具有相关实体,所有其他数据都在我的表中正确创建。除了这个产品没有什么问题。
我尝试只为一个产品实体添加种子,而不是添加其他实体,结果相同。
我监督了一些事情:还有其他实体正在被播种,所以我去看看它发生在哪里,就是在图片中添加PurchasePrice时发生的:
我的产品实体:
public class Product : BaseEntity
{
public ICollection<Supplier> Suppliers { get; set; }
public ICollection<PurchasePrice> PurchasePrices { get; set; }
}
我的供应商实体:
public class Supplier : BaseEntity
{
public ICollection<PurchasePrice> PurchasePrices { get; set; }
public ICollection<Product> Products { get; set; }
}
public class PurchasePrice:BaseEntity
{
public decimal Value { get; set; }
public Supplier Supplier { get; set; }
public Product Product { get; set; }
}
播种:
Supplier supplier1 = new Supplier("Microsoft", "Microsoft is the best supplier but its expensive", "btw nummer", "0800-123456", "microsoft@email.com", "contact person name");
ctx.Suppliers.Add(supplier1);
PurchasePrice purchaseprice = new PurchasePrice((decimal)17.70, supplier1);
ctx.PurchasePrices.Add(purchaseprice);
Product product1 = new Product("test product 1", supplier1, purchaseprice);
ctx.Products.Add(product1);
base.Seed(ctx);
有人有什么建议吗?