dbset

DbSet.Find method ridiculously slow compared to .SingleOrDefault on ID

天涯浪子 提交于 2019-12-17 07:14:52
问题 I have the following code (Database is SQL Server Compact 4.0): Dim competitor=context.Competitors.Find(id) When I profile this the Find method takes 300+ms to retrieve the competitor from a table of just 60 records. When I change the code to: Dim competitor=context.Competitors.SingleOrDefault(function(c) c.ID=id) Then the competitor is found in just 3 ms. The Competitor class: Public Class Competitor Implements IEquatable(Of Competitor) Public Sub New() CompetitionSubscriptions = New List(Of

Adapter pattern for IDbSet properties of a DbContext class

放肆的年华 提交于 2019-12-10 10:50:08
问题 Is there a way to use the method described in this answer No FindAsync() method on IDbSet for DbSet properties of a DbContext? Edit: The answer linked contains a description how to build a interface inheriting from IDbSet and adding support for the SearchAsync method of the DbSet class. I understand everything which Keith Payne has written, but I don’t know how I can use it in DbContext. For example I’ve a DbContext which looks something like this: public class MyContext : DbContext { public

Apply OrderBy with DbSet

 ̄綄美尐妖づ 提交于 2019-12-10 03:24:10
问题 I am trying to implement pagination and sorting with generic repository. How to take primary key column as default order by column in DbSet ? DbSet = Context.Set<T>(); public IQueryable<T> GetAll(int pageNumber = 0, int pageSize = 10, string sortColumn = "") { return DbSet.OrderBy("how to use primary key column here").Skip(pageNumber * pageSize)Take(pageSize); } 回答1: I have used these extension methods to achieve something similar: public static string GetKeyField(Type type) { var

What steps to get rid of Collection was modified; enumeration operation may not execute. Error?

假装没事ソ 提交于 2019-12-07 02:15:37
问题 Our programming involves some Mock testing using In-Memory Data. Therefore, we implemented the following code that would first create In-Memory Data of Customer objects // Let us create some in-memory data // Create a list of Customer List<Customer> listOfCustomers = new List<BlahBlahExample.Domain.Objects.Customer>() { new Customer { CustomerID = "1 ",Orders = new HashSet<Order>(), CustomerDemographics = new HashSet<CustomerDemographic>(), CompanyName = "Chicago Bulls", ContactName =

Adapter pattern for IDbSet properties of a DbContext class

[亡魂溺海] 提交于 2019-12-06 10:20:56
Is there a way to use the method described in this answer No FindAsync() method on IDbSet for DbSet properties of a DbContext? Edit: The answer linked contains a description how to build a interface inheriting from IDbSet and adding support for the SearchAsync method of the DbSet class. I understand everything which Keith Payne has written, but I don’t know how I can use it in DbContext. For example I’ve a DbContext which looks something like this: public class MyContext : DbContext { public DbSet<Customer> Customers { get; set; } } How can I use MyDbSet (class described in the answer.) or a

Manipulating objects with DbSet<T> and IQueryable<T> with NSubstitute returns error

会有一股神秘感。 提交于 2019-12-06 08:54:30
问题 I'd like to use NSubstitute to unit test Entity Framework 6.x by mocking DbSet. Fortunately, Scott Xu provides a good unit testing library, EntityFramework.Testing.Moq using Moq. So, I modified his code to be suitable for NSubstitute and it's been looking good so far, until I wanted to test DbSet<T>.Add() , DbSet<T>.Remove() methods. Here's my code bits: public static class NSubstituteDbSetExtensions { public static DbSet<TEntity> SetupData<TEntity>(this DbSet<TEntity> dbset, ICollection

What steps to get rid of Collection was modified; enumeration operation may not execute. Error?

最后都变了- 提交于 2019-12-05 08:16:33
Our programming involves some Mock testing using In-Memory Data. Therefore, we implemented the following code that would first create In-Memory Data of Customer objects // Let us create some in-memory data // Create a list of Customer List<Customer> listOfCustomers = new List<BlahBlahExample.Domain.Objects.Customer>() { new Customer { CustomerID = "1 ",Orders = new HashSet<Order>(), CustomerDemographics = new HashSet<CustomerDemographic>(), CompanyName = "Chicago Bulls", ContactName = "Michael Jordan", ContactTitle = "top basket ball player", Address = "332 testing lane", City = "Chicago",

Apply OrderBy with DbSet

只谈情不闲聊 提交于 2019-12-05 03:53:42
I am trying to implement pagination and sorting with generic repository. How to take primary key column as default order by column in DbSet ? DbSet = Context.Set<T>(); public IQueryable<T> GetAll(int pageNumber = 0, int pageSize = 10, string sortColumn = "") { return DbSet.OrderBy("how to use primary key column here").Skip(pageNumber * pageSize)Take(pageSize); } I have used these extension methods to achieve something similar: public static string GetKeyField(Type type) { var allProperties = type.GetProperties(); var keyProperty = allProperties.SingleOrDefault(p => p.IsDefined(typeof

Manipulating objects with DbSet<T> and IQueryable<T> with NSubstitute returns error

隐身守侯 提交于 2019-12-04 14:09:50
I'd like to use NSubstitute to unit test Entity Framework 6.x by mocking DbSet . Fortunately, Scott Xu provides a good unit testing library, EntityFramework.Testing.Moq using Moq . So, I modified his code to be suitable for NSubstitute and it's been looking good so far, until I wanted to test DbSet<T>.Add() , DbSet<T>.Remove() methods. Here's my code bits: public static class NSubstituteDbSetExtensions { public static DbSet<TEntity> SetupData<TEntity>(this DbSet<TEntity> dbset, ICollection<TEntity> data = null, Func<object[], TEntity> find = null) where TEntity : class { data = data ?? new

Is DbSet<>.Local something to use with special care?

你。 提交于 2019-12-03 16:53:47
问题 For a few days now, I have been struggling with retrieving my entities from a repository ( DbContext ). I am trying to save all the entities in an atomic action. Thus, different entities together represent something of value to me. If all the entities are 'valid', then I can save them all to the database. Entity 'a' is already stored in my repository, and needs to be retrieved to 'validate' entity 'b'. That's where the problem arises. My repository relies on the DbSet<TEntity> class which