Пример #1
0
 public IEnumerable<Client> LoadClients()
 {
     using (var context = new EfContext())
     {
         return context
             .Clients
             .Where(x => x.Name.Contains("1"))
             .Where(x => x.GroupId == 3)
             .OrderByDescending(x => x.Name)
             .ThenBy(x => x.Changed)
             .Skip(5)
             .Take(10)
             .ToList();
     }
 }
Пример #2
0
        public void ExplicitLoading()
        {
            using (var context = new EfContext())
            {
                var client = context.Clients.Find(3);

                context.Entry(client)
                    .Reference(x => x.Category)
                    .Load();

                context.Entry(client)
                    .Collection(x => x.Payments)
                    .Load();
            }
        }
Пример #3
0
        private void generateClients()
        {
            for (var i = 0; i < 500; i++)
            {
                using (var context = new EfContext())
                {
                    context.Configuration.AutoDetectChangesEnabled = false;
                    context.Configuration.ValidateOnSaveEnabled = false;

                    for (var j = 0; j < 1000; j++)
                    {
                        var client = new Client
                            {
                                Name = "client" + i + "_" + j,
                                Changed = DateTime.Now,
                                CategoryId = ((j*3 + j/7)%100) + 1,
                                GroupId = ((j*5 + j/11)%100) + 1
                            };
                        context.Entry(client).State = EntityState.Added;
                    }

                    context.SaveChanges();
                }
            }
        }
Пример #4
0
        private void generateGroups()
        {
            using (var context = new EfContext())
            {
                context.Configuration.AutoDetectChangesEnabled = false;
                context.Configuration.ValidateOnSaveEnabled = false;

                for (int i = 0; i < 100; i++)
                {
                    var group = new RiskGroup {Name = "group" + i};
                    context.Entry(group).State = EntityState.Added;
                }

                context.SaveChanges();
            }
        }
Пример #5
0
        private void generateCategories()
        {
            using (var context = new EfContext())
            {
                context.Configuration.AutoDetectChangesEnabled = false;
                context.Configuration.ValidateOnSaveEnabled = false;

                for (int i = 0; i < 100; i++)
                {
                    var category = new Category { Name = "category" + i };
                    context.Entry(category).State = EntityState.Added;
                }

                context.SaveChanges();
            }
        }