Why do Entity Framework queries not return unsaved entities

前端 未结 1 685
执念已碎
执念已碎 2020-12-09 14:58

Consider the following code:

var Products_First = (from Entities.Product p in myContext.Product  
                      select p);

Entities.Product newProdu         


        
相关标签:
1条回答
  • 2020-12-09 15:30

    Properties of type ObjectQuery<T>, like myContext.Product, always query the DB. That's what they do.

    In EF 4.1 you can use DbSet<T>.Local to query memory.

    In EF < 4.1 you would use:

    ObjectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(o => o.Entity).OfType<Product>()
    
    0 讨论(0)
提交回复
热议问题