protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
        {
            base.OnModelCreating(modelBuilder, context);

            InMemoryEntityTypeBuilderExtensions.ToQuery(
                modelBuilder.Entity <AnimalQuery>().HasNoKey(),
                () => context.Set <Bird>().Select(b => MaterializeView(b)));
        }
Пример #2
0
        public virtual void Detects_ToQuery_on_derived_keyless_types()
        {
            var modelBuilder = base.CreateConventionalModelBuilder();
            var context      = new DbContext(new DbContextOptions <DbContext>());

            InMemoryEntityTypeBuilderExtensions.ToQuery(
                modelBuilder.Entity <Abstract>().HasNoKey(), () => context.Set <Abstract>());
            InMemoryEntityTypeBuilderExtensions.ToQuery(
                modelBuilder.Entity <Generic <int> >(), () => context.Set <Generic <int> >());

            VerifyError(
                CoreStrings.DerivedTypeDefiningQuery("Generic<int>", nameof(Abstract)),
                modelBuilder.Model);
        }
Пример #3
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            InMemoryEntityTypeBuilderExtensions.ToQuery(
                modelBuilder.Entity <CustomerQuery>(),
                () => Customers.Select(
                    c => new CustomerQuery
            {
                Address      = c.Address,
                City         = c.City,
                CompanyName  = c.CompanyName,
                ContactName  = c.ContactName,
                ContactTitle = c.ContactTitle
            }));

            InMemoryEntityTypeBuilderExtensions.ToQuery(
                modelBuilder.Entity <OrderQuery>(),
                () => Orders.Select(o => new OrderQuery {
                CustomerID = o.CustomerID
            }));

            InMemoryEntityTypeBuilderExtensions.ToQuery(
                modelBuilder.Entity <ProductQuery>(),
                () => Products.Where(p => !p.Discontinued)
                .Select(
                    p => new ProductQuery
            {
                ProductID    = p.ProductID,
                ProductName  = p.ProductName,
                CategoryName = "Food"
            }));

            InMemoryEntityTypeBuilderExtensions.ToQuery(
                modelBuilder.Entity <CustomerQueryWithQueryFilter>(),
                () => Customers.Select(
                    c => new CustomerQueryWithQueryFilter
            {
                CompanyName = c.CompanyName,
                OrderCount  = c.Orders.Count(),
                SearchTerm  = SearchTerm
            }));
        }