I am having this strange behavior all of a sudden (i have compared my files in version control (tfs) to be sure i did not change anything and i didn't found anything different).
I am seeding my database with some metadata and i see that it has a very strange behavior i never saw before. I am inserting a Entity "Product" and it inserts this entity 2 times, first insert is correct and has everything it should have, the other one has NULL properties (string values) but some (like datetimes) have values.
I have totally no clue why this is happening, it is occurring when i call the base.Seed(ctx); method, that i am sure since i stopped the Webapp after this before it reached anything else.
This entity Product has related Entities, which all other data is created correctly in my tables. Nothing is wrong except this Product.
I tried to only seed 1 product entity instead of adding other as well, same results. I oversaw something: there was still other Entities being seeded so i went and see where it occurred, it was when adding the PurchasePrice in the picture that it happened:
My Product Entity:
public class Product : BaseEntity
{
public ICollection<Supplier> Suppliers { get; set; }
public ICollection<PurchasePrice> PurchasePrices { get; set; }
}
My Supplier Entity:
public class Supplier : BaseEntity
{
public ICollection<PurchasePrice> PurchasePrices { get; set; }
public ICollection<Product> Products { get; set; }
}
My PurchasePrice Entity:
public class PurchasePrice:BaseEntity
{
public decimal Value { get; set; }
public Supplier Supplier { get; set; }
public Product Product { get; set; }
}
The Seeding:
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);
No idea where i should look because nothing changed in my model, neither in my way of seeding. I tried using AddOrUpdate() but that didn't worked.
I am using EF6 in a MVC web app using Code-first approach no migrations(yet). Anyone has any suggestion please?