entity-framework-6.1

Persist Entity Framework query cache

痞子三分冷 提交于 2019-11-29 15:36:25
问题 I have an ASP.NET MVC 5 web-application and use EF 6.1 to access my DB. I have some rather complex LINQ queries which take up to 10s to compile, but then execute in a few milliseconds. EF does cache this queries fine and the second time the query is executed it returns within this few milliseconds. But this cache is not persisted so on every app-restart the query needs to be recompiled, which takes that 10s again. Is there a way to persist this query cache so it survives an app-restart? 回答1:

EF performing a select on every insert with Identity column

独自空忆成欢 提交于 2019-11-28 10:51:46
问题 I have noticed that when I insert with EF, it performs a select to find the next PK. I have a PK field with Identity set and auto-increment enabled. Here is the Query SELECT [ackId] FROM [dbo].[Acks] WHERE @@ROWCOUNT > 0 AND [ackId] = scope_identity() I happened to notice it as it was at the top of the Recent Expensive Queries List in SQL Manger Studio. It doesn't quite make sense that the query to find the PK is more expensive than the actual insert? Is this normal behaviour? Or is this

The specified type member 'UsersCount' is not supported in LINQ to Entities

让人想犯罪 __ 提交于 2019-11-28 10:21:05
问题 I have such POCO entity public class Product : Entity { [DatabaseGenerated(DatabaseGeneratedOption.None)] public int Id { get; set; } [Required] [MaxLength(50)] public string Name { get; set; } public virtual ICollection<Order> Orders { get; set; } [NotMapped] public int UsersCount { get { return Orders.Count(); } } } Product access method public IQueryable<Product> GetAll() { return _context.Product.Include(I=>I.Orders); } When I load all products into View var model = _productService.GetAll

Unable to update Foreign Key in Entity Framework 6

百般思念 提交于 2019-11-27 18:49:10
问题 I am trying to do a simple update to the foreign key but the script never get sent over. Here is the code I am using: using (var db = new MyContext()) { db.Entry<Contact>(newContact).State = EntityState.Modified; newContact.ContactOwner = db.Person.Find(3); db.SaveChanges(); } EF6 update the rest of the column in the Persons table but it is not updating the Contact_Id in Persons table. Person entity: public class Person { public int Id { get; set; } public string Name { get; set; } public