Refresh EF 6 DBContext

c# entity-framework entity-framework-6

Question

When using Entity Framework 6, I have a product object with a list of variants that looks like this:

public class Product
{
    public int ProductId { get; set;}

    public virtual ICollection<Variant> Variants { get; set;}

    ... other properties
}

public class Variant
{
    public int VariantId { get; set;}

    public int ProductId { get; set;}

    public virtual Product Product { get; set;}

    public int StoreId { get; set;}

    ... other properties
}

And I make use of this to extract the goods from the situation:

public static GetProducts()
{
    using (MyDBContext context = new MyDBContext())
    {
        return context.Products.Include(p => p.Variants);
    }
}

Now that everything is working properly, when I get theProduct It returns with the variations. But this morning I erroneously used theProduct instead of a DTO and sorted the variants according to aStoreId now whenever I receive aProduct only the versions for that store are returned (even though I never committed any changes).

How can I reset my context so that I may obtain all the variants again? I verified the database and all the variants are still there.

I've tried these things:

  • setting up iis
  • cleaning and reassembling the remedy
  • adding a new property by altering the object
  • Reloading the item with:

    foreach (Product product in context.Products)
    {
        context.Entry(product).Reload();
    }
    

Is there anything else I can try to reset the context but nothing appears to work?

1
0
4/23/2015 2:59:45 PM

Accepted Answer

ZZZ_tmp
0
4/24/2015 2:10:56 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow